By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,983 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,983 IT Pros & Developers. It's quick & easy.

Thread Question: Sleeping thread changes to stopped on its own.

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
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
Nov 15 '05 #2

P: n/a
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

Nov 15 '05 #3

P: n/a
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.

Nov 15 '05 #4

P: n/a
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.


Nov 15 '05 #5

P: n/a
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

Nov 15 '05 #6

P: n/a
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.



Nov 15 '05 #7

P: n/a
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


Nov 15 '05 #8

P: n/a
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


Nov 15 '05 #9

P: n/a
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



Nov 15 '05 #10

P: n/a
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.
>
>



Nov 15 '05 #11

P: n/a
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
Nov 15 '05 #12

P: n/a
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
Nov 15 '05 #13

P: n/a
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
Nov 15 '05 #14

P: n/a
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

Nov 15 '05 #15

P: n/a
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.

Nov 15 '05 #16

P: n/a
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
Nov 15 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.