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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Apr 11, 2010, 7:37 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 10, 2010, 11:42 PM EDT
GustavoRank #1,990 · 732 reputationPosted Apr 11, 2010, 8:12 AM EDT
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 HobbsRank #107 · 20.5K reputationPosted Apr 11, 2010, 9:47 AM EDT
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.
GustavoRank #1,990 · 732 reputationPosted Apr 11, 2010, 9:52 AM EDT
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
GustavoRank #1,990 · 732 reputationPosted Apr 11, 2010, 7:59 PM EDT
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.