エラーが発生したときに間隔を増やす必要があるWindowsサービス内にタイマージョブがあります。私の問題は、実際に間隔を変更するためにtimer.Changeメソッドを取得できないということです。 "DoSomething"は、常に最初の間隔の後に呼び出されます。Windowsサービスのタイマー間隔を変更する
コードは次のとおりです。
protected override void OnStart(string[] args)
{
//job = new CronJob();
timerDelegate = new TimerCallback(DoSomething);
seconds = secondsDefault;
stateTimer = new Timer(timerDelegate, null, 0, seconds * 1000);
}
public void DoSomething(object stateObject)
{
AutoResetEvent autoEvent = (AutoResetEvent)stateObject;
if(!Busker.BitCoinData.Helpers.BitCoinHelper.BitCoinsServiceIsUp())
{
secondsDefault += secondsIncrementError;
if (seconds >= secondesMaximum)
seconds = secondesMaximum;
Loggy.AddError("BitcoinService not available. Incrementing timer to " +
secondsDefault + " s",null);
stateTimer.Change(seconds * 100, seconds * 100);
return;
}
else if (seconds > secondsDefault)
{
// reset the timer interval if the bitcoin service is back up...
seconds = secondsDefault;
Loggy.Add ("BitcoinService timer increment has been reset to " +
secondsDefault + " s");
}
// do the the actual processing here
}
愚かな私。それは簡単です。ありがとうございました! – AyKarsi