A
Alvin Bruney
I'm observing that a sleeping thread changes to stopped after a while. Is
that accepted framework behavior for web applications?
My thread basically does some work, and sleeps for 60 minutes before calling
itself recursively, which means it is supposed to run on the hour every
hour. But it automatically stops after 2 hours. I only get 2 emails, 1 per
hour and then nothing. When I examine the threadstate during run-time, it
has changed from background, waitsleepjoin to stopped. I'm just letting the
app sit there so I know nothing else is going on in the background. Here's
the code.
//I manually start the thread when the application launches
RateManager.GateKeeper worker = new
RateManager.GateKeeper("localhost",System.Configuration.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSetti
ngs["fromEmail"],"GateKeeper is initializing","GateKeeper Init");
//maintain a global handle so that i can examine thread behavior at runtime
GlobalRateMan.GateKeeperMonitor = new Thread (new ThreadStart
(RateManager.GateKeeper.Analyze));
GlobalRateMan.GateKeeperMonitor.Priority = ThreadPriority.Lowest;
GlobalRateMan.GateKeeperMonitor.Name = "GateKeeper";
GlobalRateMan.GateKeeperMonitor.IsBackground= true;
GlobalRateMan.GateKeeperMonitor.Start();
//change the text on the button to paused - webding font
GateKeeper.Text = ";";
GateKeeper.ToolTip =
RateManager.GlobalRateMan.GateKeeperMonitor.ThreadState.ToString();
//here is Analyze
Email(); //usual email code
System.Threading.Thread.Sleep(TimeSpan.FromMinutes(Double.Parse(GlobalRateMa
n.GateKeeperSleepTime))); //60 minutes
RateManager.GateKeeper.Subject = "GateKeeper is preparing to run Analysis
from Netapp-1";
[snip]
//work gets done here
//recursion controlled by sleeptime
Analyze();
When I examine the state of the thread thru the
GlobalRateMan.GateKeeperMonitor handle which is a static handle holding the
address of the thread,
it is stopped after about 2 hours. On another related note, I am noticing
other weird behavior like this thread will refuse to email if it is started
from the application_start event.
that accepted framework behavior for web applications?
My thread basically does some work, and sleeps for 60 minutes before calling
itself recursively, which means it is supposed to run on the hour every
hour. But it automatically stops after 2 hours. I only get 2 emails, 1 per
hour and then nothing. When I examine the threadstate during run-time, it
has changed from background, waitsleepjoin to stopped. I'm just letting the
app sit there so I know nothing else is going on in the background. Here's
the code.
//I manually start the thread when the application launches
RateManager.GateKeeper worker = new
RateManager.GateKeeper("localhost",System.Configuration.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSetti
ngs["fromEmail"],"GateKeeper is initializing","GateKeeper Init");
//maintain a global handle so that i can examine thread behavior at runtime
GlobalRateMan.GateKeeperMonitor = new Thread (new ThreadStart
(RateManager.GateKeeper.Analyze));
GlobalRateMan.GateKeeperMonitor.Priority = ThreadPriority.Lowest;
GlobalRateMan.GateKeeperMonitor.Name = "GateKeeper";
GlobalRateMan.GateKeeperMonitor.IsBackground= true;
GlobalRateMan.GateKeeperMonitor.Start();
//change the text on the button to paused - webding font
GateKeeper.Text = ";";
GateKeeper.ToolTip =
RateManager.GlobalRateMan.GateKeeperMonitor.ThreadState.ToString();
//here is Analyze
Email(); //usual email code
System.Threading.Thread.Sleep(TimeSpan.FromMinutes(Double.Parse(GlobalRateMa
n.GateKeeperSleepTime))); //60 minutes
RateManager.GateKeeper.Subject = "GateKeeper is preparing to run Analysis
from Netapp-1";
[snip]
//work gets done here
//recursion controlled by sleeptime
Analyze();
When I examine the state of the thread thru the
GlobalRateMan.GateKeeperMonitor handle which is a static handle holding the
address of the thread,
it is stopped after about 2 hours. On another related note, I am noticing
other weird behavior like this thread will refuse to email if it is started
from the application_start event.