私は2つのタイマーを実行するWindowsサービスを持っています.1つは24時間に15分間隔で実行します。 イベントロギングを追加して、経過イベントハンドラが15分に発生しているように見えますが、そうではないように見えます。誰もがこのコードで間違ったものを見ることができますか?Windowsサービスが経過イベントハンドラを起動しない
public partial class GTstaging : ServiceBase
{
System.Timers.Timer regularTimer = new System.Timers.Timer();
System.Timers.Timer longTimer = new System.Timers.Timer();
DateTime _scheduleTime;
public staging()
{
InitializeComponent();
_scheduleTime = DateTime.Today.AddDays(1).AddHours(Convert.ToDouble(ConfigurationManager.AppSettings["ScheduleTime_" + DateTime.Now.DayOfWeek.ToString()]));
}
protected override void OnStart(string[] args)
{
//** original - ConsoleApplication1.Program.DoProcessing();
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry("START, regular timer:" + ConfigurationManager.AppSettings["RegularTimer"], EventLogEntryType.Information, 101, 1);
}
this.regularTimer.Enabled = true;
this.regularTimer.Interval = Convert.ToDouble(ConfigurationManager.AppSettings["RegularTimer"]);
this.regularTimer.AutoReset = true;
this.regularTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.DoRegular);
this.longTimer.Enabled = true;
this.longTimer.Interval = _scheduleTime.Subtract(DateTime.Now).TotalSeconds * 1000;
this.longTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.DoLongRunning);
}
private void DoRegular(object sender, System.Timers.ElapsedEventArgs e)
{
//do stuff then log
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry("Regular Process End", EventLogEntryType.Information, 101, 1);
}
}
private void DoLongRunning(object sender, System.Timers.ElapsedEventArgs e)
{
//do stuff
}
protected override void OnStop()
{
this.regularTimer.Stop();
this.longTimer.Stop();
this.regularTimer = null;
this.longTimer = null;
}
}
}
'ConfigurationManager.AppSettings [" RegularTimer "]'をeventLogに書き込むときの設定は何ですか? –
こんにちは、それは900000 – DarkW1nter
イベントログではなく 'DoRegular'イベントハンドラでファイルに書き込もうとしたのだろうかと思います。私はあなたが2つの異なるスレッド(サービスのメインスレッドとタイマーイベントハンドラ)でログにアクセスしていると思います。だからあなたの出来事は発砲しているかもしれませんが、ロギングのためにあなたは偽陰性を見ています。 [このMSDNのページを確認](https://msdn.microsoft.com/en-us/library/0680sfkd.aspx) –