|
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.Configur ation.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet ti
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.Thread State.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. | |
Share:
|
Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: 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.
It sounds like there's a fault in your recursion. Could you produce a
short but complete example which demonstrates the problem?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too | | |
Yeah, this doesn't sound like an obvious use of recursion. Most
applications that would use Sleep in this way would be iterative, inside a
while(true) loop. Put some code out here that shows the problem.
Also, try lowering your Sleep time and see if it drops out after two
recursions, after two hours, or if it keeps going.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: 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.
It sounds like there's a fault in your recursion. Could you produce a short but complete example which demonstrates the problem?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too | | |
Hi,
I don't really know what's wrong with your code. But is there a specific
reason why you use recursion ?
Recursion:
An A=method n=invocation nr
A0 calls A
A1 calls A
A2 calls A
A3 doesn't call A
cleanup A3->A2->A1->A0
Since cleanup is delayed, it causes an overhead. And recursion can only
work well if at a certain point the function doesn't call itself anymore.
I would not use recursion in your case.
Do you have a try/catch inside Analyse ?
HTH
greetings
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:up*************@TK2MSFTNGP12.phx.gbl... 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.Configur ation.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet ti 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.Thread State.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.
| | |
No, that's not the idea.
Main thread spawns child thread. Child thread calls method. Method sleeps,
wakes up does some work, calls itself (Method sleeps, wakes up does some
work, calls itself...)
why use recursion? because it easily accomplishes what i'm after with my
tite deadline.
The recursion looks like this
Method()
{
Thread.Sleep(60);
//do work
Method();
}
"Jhon" <Jh**@a.a> wrote in message
news:Sq*********************@phobos.telenet-ops.be... Hi,
I don't really know what's wrong with your code. But is there a specific reason why you use recursion ?
Recursion: An A=method n=invocation nr
A0 calls A A1 calls A A2 calls A A3 doesn't call A cleanup A3->A2->A1->A0
Since cleanup is delayed, it causes an overhead. And recursion can only work well if at a certain point the function doesn't call itself anymore.
I would not use recursion in your case.
Do you have a try/catch inside Analyse ?
HTH greetings
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in message news:up*************@TK2MSFTNGP12.phx.gbl... 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.Configur ation.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet ti 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.Thread State.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.
| | |
Question:
In writing a short demo, i've realized that this code is inherently flawed.
It will pop the stack (memory exhaustion) after a couple days of running
right because stack space isn't infinite?
Might there be a better way to do this.
method()
{
Sleep(5)
//work
method()
}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: 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.
It sounds like there's a fault in your recursion. Could you produce a short but complete example which demonstrates the problem?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too | | |
Hi,
<see inline>
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:e%****************@tk2msftngp13.phx.gbl... No, that's not the idea. Main thread spawns child thread. Child thread calls method. Method sleeps, wakes up does some work, calls itself (Method sleeps, wakes up does some work, calls itself...)
why use recursion? because it easily accomplishes what i'm after with my tite deadline. The recursion looks like this Method() { Thread.Sleep(60); //do work Method(); }
Well , that's what I'm saying, it's bad. Method cannot keep calling Method,
at a certain time, Method should stop calling Method. (e.g. recursion for
Fractorial)
The first Method call can't finish until the second did, and so
on....keeping all methods open until your thread finishes.
Recursion really doesn't help you _here_. It should be more easy with a
while loop.
HTH
greetings
"Jhon" <Jh**@a.a> wrote in message news:Sq*********************@phobos.telenet-ops.be... Hi,
I don't really know what's wrong with your code. But is there a
specific reason why you use recursion ?
Recursion: An A=method n=invocation nr
A0 calls A A1 calls A A2 calls A A3 doesn't call A cleanup A3->A2->A1->A0
Since cleanup is delayed, it causes an overhead. And recursion can only work well if at a certain point the function doesn't call itself
anymore. I would not use recursion in your case.
Do you have a try/catch inside Analyse ?
HTH greetings
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote
in message news:up*************@TK2MSFTNGP12.phx.gbl... 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.Configur ation.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet ti 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.Thread State.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.
| | |
The stack is set to 1MB. Why not just code the loop:
while (true)
{
DoStuff(); //whatever you do every 60 minutes
sleep(SixtyMinutes);
}
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:ui**************@TK2MSFTNGP12.phx.gbl... Question: In writing a short demo, i've realized that this code is inherently
flawed. It will pop the stack (memory exhaustion) after a couple days of running right because stack space isn't infinite?
Might there be a better way to do this.
method() { Sleep(5) //work method() }
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: 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.
It sounds like there's a fault in your recursion. Could you produce a short but complete example which demonstrates the problem?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
| | |
d'oh
A timer.
Don't know why i didn't think of this before(well i thought of it but i
thought it wouldn't work on the web).
I put a timer on there, and it is working, (not perfectly because it fires 3
events after the elapsed time and i only want one event) but that will
definitely work for now.
I played with the advanced properties a bit. This thing will actually let
you configure properties and then it will take the properties and persist it
in the webconfig file. All behind the scenes. talk about neat.
thanks
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:ui**************@TK2MSFTNGP12.phx.gbl... Question: In writing a short demo, i've realized that this code is inherently
flawed. It will pop the stack (memory exhaustion) after a couple days of running right because stack space isn't infinite?
Might there be a better way to do this.
method() { Sleep(5) //work method() }
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: 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.
It sounds like there's a fault in your recursion. Could you produce a short but complete example which demonstrates the problem?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
| | |
Because the while construct is a very in-efficient wait state in terms of
cpu cycles.
"Fred Mellender" <no****************@frontiernet.net> wrote in message
news:s9*****************@news02.roc.ny... The stack is set to 1MB. Why not just code the loop:
while (true) { DoStuff(); //whatever you do every 60 minutes sleep(SixtyMinutes); } "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in message news:ui**************@TK2MSFTNGP12.phx.gbl... Question: In writing a short demo, i've realized that this code is inherently flawed. It will pop the stack (memory exhaustion) after a couple days of running right because stack space isn't infinite?
Might there be a better way to do this.
method() { Sleep(5) //work method() }
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: > 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.
It sounds like there's a fault in your recursion. Could you produce a short but complete example which demonstrates the problem?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
| | |
point taken. a while loop suffers from cpu burn cycle syndrome as well.
i've used a timer, it seems to be working. A timer actually waits on a
different thread so it doesn't consume near as much resources.
"Jhon" <Jh**@a.a> wrote in message
news:A5*********************@phobos.telenet-ops.be... Hi, <see inline>
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in message news:e%****************@tk2msftngp13.phx.gbl... No, that's not the idea. Main thread spawns child thread. Child thread calls method. Method
sleeps, wakes up does some work, calls itself (Method sleeps, wakes up does some work, calls itself...)
why use recursion? because it easily accomplishes what i'm after with my tite deadline. The recursion looks like this Method() { Thread.Sleep(60); //do work Method(); } Well , that's what I'm saying, it's bad. Method cannot keep calling
Method, at a certain time, Method should stop calling Method. (e.g. recursion for Fractorial) The first Method call can't finish until the second did, and so on....keeping all methods open until your thread finishes.
Recursion really doesn't help you _here_. It should be more easy with a while loop.
HTH greetings
"Jhon" <Jh**@a.a> wrote in message news:Sq*********************@phobos.telenet-ops.be... Hi,
I don't really know what's wrong with your code. But is there a specific reason why you use recursion ?
Recursion: An A=method n=invocation nr
A0 calls A A1 calls A A2 calls A A3 doesn't call A cleanup A3->A2->A1->A0
Since cleanup is delayed, it causes an overhead. And recursion can
only work well if at a certain point the function doesn't call itself anymore. I would not use recursion in your case.
Do you have a try/catch inside Analyse ?
HTH greetings
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in message news:up*************@TK2MSFTNGP12.phx.gbl... > 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.Configur ation.ConfigurationSetting >
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet ti > 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.Thread State.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. > >
| | |
hi, "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:e8**************@TK2MSFTNGP09.phx.gbl... point taken. a while loop suffers from cpu burn cycle syndrome as well. i've used a timer, it seems to be working. A timer actually waits on a different thread so it doesn't consume near as much resources.
Polling in a while loop is bad for cpu cycles, something like:
while ( form.Blabla != "klkk" ) { /*just wait, do nothing*/ };
But you aren't doing that, each loop you sleep an hour and sleeping doesn't
cause cpu cycles, you should see it in the right context.
Nevertheless using a Timer is a good way too.
HTH
greetings | | |
Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: Because the while construct is a very in-efficient wait state in terms of cpu cycles.
Not with the "sleep(SixtyMinutes)" bit in there. Fred wasn't suggesting
a tight loop.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too | | |
Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: point taken. a while loop suffers from cpu burn cycle syndrome as well. i've used a timer, it seems to be working. A timer actually waits on a different thread so it doesn't consume near as much resources.
What makes you think that a while loop with a sleep in would consume
lots of resources?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too | | |
well for one, the loop construct has to be loaded to execute, but then it
does nothing because the main thread is sleeping so it gets removed from cpu
queue, only to be reloaded again after the timer event fires. That is a burn
cycle because the cpu load resulted in no real work being done.
can you tell i'm grasping?
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: point taken. a while loop suffers from cpu burn cycle syndrome as well. i've used a timer, it seems to be working. A timer actually waits on a different thread so it doesn't consume near as much resources.
What makes you think that a while loop with a sleep in would consume lots of resources?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too | | |
i thought about this code i put out and i feel i must apologize for this
terrible code. jeez talk about a poor idea in production...
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:up*************@TK2MSFTNGP12.phx.gbl... 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.Configur ation.ConfigurationSetting
s.AppSettings["toEmail"],System.Configuration.ConfigurationSettings.AppSet ti 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.Thread State.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.
| | |
Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote: well for one, the loop construct has to be loaded to execute, but then it does nothing because the main thread is sleeping so it gets removed from cpu queue, only to be reloaded again after the timer event fires. That is a burn cycle because the cpu load resulted in no real work being done.
can you tell i'm grasping?
Yup :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too | | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
9 posts
views
Thread by Harald Armin Massa |
last post: by
|
1 post
views
Thread by COMfused |
last post: by
|
7 posts
views
Thread by Morris |
last post: by
|
2 posts
views
Thread by juky |
last post: by
|
17 posts
views
Thread by Benny Raymond |
last post: by
| |
9 posts
views
Thread by =?Utf-8?B?anAybXNmdA==?= |
last post: by
|
2 posts
views
Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post: by
|
2 posts
views
Thread by Steve |
last post: by
| | | | | | | | | | |