I have a window service and i'm using System.Timers.Timer to schedule my service
protected override void OnStart(string[] args)
{
timer_= new System.Timers.Timer(intervalTime * 1000);
timer_.Elapsed += new System.Timers.ElapsedEventHandler(TimerEvent);
timer_.Enabled = true;
}
private void TimerEvent(object sender, System.Timers.ElapsedEventArgs e)
{
DoSth();
}
I find that, the Dosth() function doesn't run exactly when i start the service, but after intervalTimer seconds.I want it to run exactly after i start the service, so i call the function Dosth() before statment timer_.Enabled = true;. But i got another problem that. the distance of the 1st and the 2nd process is not exactly equal intervalTime, but base on processing time of DoSth() function. How can i solve this?