Hello:
I have a Thread running and I would like to pause it and later resume it. I was trying to use:
Thread.CurrentThread.Suspend();
But it seems its been obsoleted. Anyone know how else i can do it?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Apr 11, 2010, 11:37 PM
GustavoPosted Apr 11, 2010, 11:59 PM
Well, I am writing a routine to do some updates or check my tables and do updates to it if needed. The update might run for a long time.
You got me thining... Maybe I should press the 'Stop' button and ask if I really want to 'Pause' and if the answer is no then 'Continue' else do the real 'Stop'.
That command: Thread.CurrentThread.Suspend(); Seemed so simple that I just wanted to use it.
GustavoPosted Apr 11, 2010, 1:52 PM
Reason I want it to Suspend is just to have it pause the update, untill I click the 'Continue' to resume the update or click 'Stop' to really stop it.
I have the run and stop of the Thread working perfectly...
I will research the key words that you gave me.
Thanks
Sam HobbsPosted Apr 11, 2010, 1:47 PM
Without knowing the details of why the thread needs to be suspended, my best guess of what is the best fit for you to use is the EventWaitHandle class. The event should be created with an initialState of signaled and mode ManualReset.
You will need to have someplace in the worker thread to check the event to see if it is nonsignaled and when it is nonsignaled wait for it to be signaled. In the main thread, instead of using Suspend, reset the event to nonsignaled and when the worker thread is to resume set the event to signaled. I hope I have the terms set, reset, singaled and nonsignaled correct.
GustavoPosted Apr 11, 2010, 12:12 PM
It says: System.Threading.Thread.Suspend() is obsolete. Thread.Suspend has been deprecated. PLlease use other classes in System.Threading, such as Monitor, Mutex, Event and Semaphore....
I found samples of code on how I would like to use it, but I cant find samples of the others: Monitors...
Sam HobbsPosted Apr 11, 2010, 3:42 AM