That's fine, however the thing you showed me is still sleeping - I need
to be able to wake up the sleeping thread, or terminate it (is that when
abort comes into play?)
Basically what I need to do is this:
* ClientA needs to be run every 5 minutes
* If SettingX changes to false, it allows ClientA to finish running
(if it's currently running) but it will no longer run again.
* If SettingX changes to true, it tells ClientA to start back up on
it's 5 minute cycle again.
* If App closes, it allows ClientA to finish running (if it's
currently running) but it will no longer run again.
What I was doing before (which I can see why it's wrong now but not how
to do it correctly):
* ClassX creates ClientA class
* ClassX sets loop_bool in ClientA to true
* ClassX starts ClientA thread
* ClientA thread runs and sleeps at the end
* When ClientA is done sleeping it loops, checks the loop_bool and
continus running if loop_bool is true.
* SettingX in ClassX changes
* ClassX sets loop_bool in ClientA to false
* ClassX Resumes ClientA thread
* ClassX Joins ClientA
* ClientA finishes and doesn't loop
* ClassX checks setting to see if it's true, if so it starts up the
ClientA thread again
Please help me.. haha :)
~Benny
Jon Skeet [C# MVP] wrote:[color=blue]
> Benny Raymond wrote:
>[color=green]
>>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 marking the bool to
>>false which would cause the thread to finish what it was doing and
>>complete, or to wake up for it's sleep state and not loop back into
>>itself anymore.
>>
>>How do we tell a thread to stop sleeping now that Thread.Resume is obsolete?[/color]
>
>
> You use Monitor.Wait/Pulse or WaitHandles, which is what you should
> have been doing before :)
>
> See
http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml (half
> way down) for a sample of this.
>
> Jon
>[/color]