Thread.Suspend and Thread.Resume can give unpredictable results, and both methods have been deprecated. Indeed, if
Thread.Suspend is not used very carefully, a thread can be suspended while
holding a lock, thus leading to a deadlock.
There are other synchronization mechanisms that are safer and should be used instead, such as:
-
Monitor provides a mechanism that synchronizes access to objects.
-
Mutex provides a mechanism that synchronizes interprocess access to a protected resource.
-
Semaphore provides a mechanism that allows limiting the number of threads that have access to a protected resources concurrently.
-
Events enable a class to notify others when something of interest occurs.