The Thread.Abort()
documentation states that it will throw ThreadStateException
if:
The thread that is being aborted is currently suspended.
What circumstance is this exactly?
If, for example, the thread is in the middle of a Thread.Sleep(1000)
, or waiting on a WaitHandle
, is it considered "suspended"?
From reading the documentation, it is my interpretation that "suspended" in this context does not relate to the use of Thread.Sleep
or WaitHandle
usage, but instead refers to the thread state encountered when using the obsoleted Thread.Suspend
or equivalent Windows API SuspendThread
.
In this context, a suspended thread is a thread whose execution has been explicitly paused (or suspended), i.e. it's context is no longer being executed but has been suspended to be resumed at some later point.
This technique is primarily used by debuggers and is not recommended for sychronization activities. This is clarified in the MSDN documentation on SuspendThread
:
This function is primarily designed for use by debuggers. It is not intended to be used for thread synchronization. Calling SuspendThread on a thread that owns a synchronization object, such as a mutex or critical section, can lead to a deadlock if the calling thread tries to obtain a synchronization object owned by a suspended thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With