Hi there,
Im using a Timer with an interval of 1 min (60000 milliseconds) to start a thread in the Global.cs of my application. Everything works fine until the the thread job takes more than 1 min to complete. When the job takes longer that 1 min, the old (currently running) job never seems to get to completion.
Basically I only want to re-run the thread once its complete but using the Timer so I can potentially leave gaps inbetween each Thread jobcall.
ANY help would be appreciated!
I list the code in my Global.cs file below:
Im using a Timer with an interval of 1 min (60000 milliseconds) to start a thread in the Global.cs of my application. Everything works fine until the the thread job takes more than 1 min to complete. When the job takes longer that 1 min, the old (currently running) job never seems to get to completion.
Basically I only want to re-run the thread once its complete but using the Timer so I can potentially leave gaps inbetween each Thread jobcall.
ANY help would be appreciated!
I list the code in my Global.cs file below:
Code:
protected void Application_Start(Object sender, EventArgs e) {
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnPopulateDatabaseFromDynamicDataSource);
aTimer.Interval = 60000; // Every min
aTimer.Enabled = true;
}
private static void OnPopulateDatabaseFromDynamicDataSource(object source, System.Timers.ElapsedEventArgs e) {
try {
System.Threading.Thread objWorkerThread
= new System.Threading.Thread(HelperClass.PopulateDBFromDynaDataSource);
objWorkerThread.Name = "DynaPopulate";
objWorkerThread.IsBackground =
true;
objWorkerThread.Start();
}
catch (Exception ex) {
// Do nothing for now!!
}
}
Comment