L
linesh.gajera
Hi Guys,
I am creating a Windows service that call a routine at given interval.
Once routine is complete, windows service should wait for 5 minutes and
then call the routine again. I was using System.Timers.Timer but i had
to remove it because of known bug(842739). Now i am using
System.Threading.Timer. It executes routine fine but the delay time is
sporadic, sometimes it executes routine after 5 minutes, sometimes 10
minuete, 13 minuntes. I want to wait exactly 5 mintes before it call
the routine. Here is my code snippet. I don't know how to fix it.
private Timer eventTimer;
private bool ProcessInProgress = false;
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
TimerCallback eventCallBack = new TimerCallback(this.OnTimer);
eventTimer = new
Timer(eventCallBack,this,System.Threading.Timeout.Infinite,System.Threading.Timeout.Infinite);
//Here window service should wait for 5 mintes before call the routine
eventTimer.Change(300000,0);
}
public void OnTimer(Object source)
{
if(ProcessInProgress == false)
{
//RunTMService routine is called
RunTMService();
//Once RunTMService routine is complete, timer should wait for 5
more minutes and exeucte the routine again.
eventTimer.Change(300000,0);
}
}
private void RunTMService()
{
try
{
ProcessInProgress = true;
//Here perform all database activites and business logic
}
catch{}
finally
{
ProcessInProgress = false;
}
}
I don't understand why Timer does not exeute exactly after 5 minutes.
It is very sporadic. Any clue? Direction?
I am creating a Windows service that call a routine at given interval.
Once routine is complete, windows service should wait for 5 minutes and
then call the routine again. I was using System.Timers.Timer but i had
to remove it because of known bug(842739). Now i am using
System.Threading.Timer. It executes routine fine but the delay time is
sporadic, sometimes it executes routine after 5 minutes, sometimes 10
minuete, 13 minuntes. I want to wait exactly 5 mintes before it call
the routine. Here is my code snippet. I don't know how to fix it.
private Timer eventTimer;
private bool ProcessInProgress = false;
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
TimerCallback eventCallBack = new TimerCallback(this.OnTimer);
eventTimer = new
Timer(eventCallBack,this,System.Threading.Timeout.Infinite,System.Threading.Timeout.Infinite);
//Here window service should wait for 5 mintes before call the routine
eventTimer.Change(300000,0);
}
public void OnTimer(Object source)
{
if(ProcessInProgress == false)
{
//RunTMService routine is called
RunTMService();
//Once RunTMService routine is complete, timer should wait for 5
more minutes and exeucte the routine again.
eventTimer.Change(300000,0);
}
}
private void RunTMService()
{
try
{
ProcessInProgress = true;
//Here perform all database activites and business logic
}
catch{}
finally
{
ProcessInProgress = false;
}
}
I don't understand why Timer does not exeute exactly after 5 minutes.
It is very sporadic. Any clue? Direction?