我想在一個應該以固定的時間間隔執行動作的Windows服務中使用計時器而不是睡眠。在Windows服務中使用計時器
可以說我有以下班級。
class MailManagerClient
{
//fields
string someString
//Constructor
public MailManagerClient()
{
aTimer = new System.Timers.Timer(30000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Enabled = true
}
//methode
public bool DoSomthingIncConstantInterval()
{
//Do Somthing
return true;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
DoSomthingIncConstantInterval()
}
}
而且我也有與OnStart
方法的窗口服務。
我知道在OnStart
方法中,我需要爲類型MailManagerClient
啓動一個新線程。
但我該如何啓動線程?哪個方法應該是新線程的入口點?
該線程應該如何保持活動狀態?
也許你應該看看quartz.net,我認爲它會更好地爲你的目的服務。 – alxbrd 2012-04-04 15:21:15
[System.Reactive.Linq](http://msdn.microsoft.com/zh-cn/library/hh229435(v = vs.103).aspx)中的Observable.Timer也是其他內容。 – 2012-04-04 15:22:55