Why is not recommended to use Thread.Resume() and Thread.Suspend()?

The question was asked: 49 years 10 months ago   views: 29
Why is not recommended to use Thread.Resume() and Thread.Suspend()?
Not in principle, "not recommended" not recommended for stop-restart the process that implements the stream. This is because a Suspend can pause a thread in "the wrong place", the renewal of which may lead to different access errors. - 25-01-2013 в 13:41:24

Answers   2


It is not recommended to use them incorrectly.

But if by the rules, then Thered.Resume() should cause the other thread (for obvious reasons, not the thread itself may remove the pause), but Thered.Suspend() must call thread only himself. Another thread to call this method, as it is unclear exactly where it will stop.

And do not recommend them because there are a lot of good and different synchronization methods: critical sections, mutex, events, semaphores, and so on.

Answered: 25-01-2013 в 13:34:54
You have not answered as "wrong" and why not recommend. ".. and don't recommend to go on a construction site without a helmet, because there are many good and different ways to protect your head helmets, umbrellas, etc." - 19-05-2017 в 09:55:46
Paraphrasing especially for those who think that I didn't answer. You can say so that Resume is a green light, and Suspend is the brake pedal. the other thread is a different person from the driver. And if someone else was pushing the brake, it could be anything. - 19-05-2017 в 09:58:57

Taken from here - section #Suspend and Resume:

  • From .NET 2.0, Suspend and Resume have been deprecated, their use discouraged because of the danger inherent in arbitrarily suspending another thread. If a thread holding a lock on a critical resource is suspended, the whole application (or computer) can deadlock.

  • This is far more dangerous than calling Abort — which results in any such locks being released (at least theoretically) by virtue of code in finally blocks.

Answered: 25-01-2013 в 14:01:08
What is worse, you can not predict, does not hold if the current thread is the lock. For example, it can be in native code and keep up to that moment, the lock on a heap-consider that your process has died. - 25-01-2013 в 15:50:54