473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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
16 2027
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Harald Armin Massa | last post by:
I need to do some synchronisations like in a cron.job import time from threading import Thread class updater(Thread): def run(self): while True: do_updates() time.sleep(600)
1
by: COMfused | last post by:
I have a thread that has a delegate function which will be called when another process exits. This thread went to sleep, the process exits and is supposed to call the delegate, but it did not...
7
by: Morris | last post by:
I want to abort a running thread, so I call MyThread.abort() function. My problem is this thread runs "almost" like a while(true) loop and I don't want the Abort() function interrupts the thread at...
2
by: juky | last post by:
Hi all, I have a loop in the thread checking for a particular service status, whenever the status changes to "stopped" a RaiseEvent is generated by thread and another function runs. At the same...
17
by: Benny Raymond | last post by:
I have a thread that sleeps for 5 minutes once it's finished running a method and then it repeats itself if it's supposed to (bool = true). Prior to 2.0 I was able to resume the thread after...
0
by: Buckaroo Banzai | last post by:
Hello, newbie here... I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the...
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a thread ABC that starts another thread XYX. Thread XYZ monitors various things and if there is no work to do it calls Thread.Sleep to sleep for a minute or so. Occasionally...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.