Thread.Sleep(5000);
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds);
Thread.suspend(5000);
Console.WriteLine(stopwatch.ElapsedMilliseconds);
Sleep is used on a single thread and it suspends a thread for a period of time. Whereas suspend is deprecated.
Wait() method releases lock during Synchronization. Sleep() method does not release the lock on object during Synchronization.
Sleep() method will immediately place the thread under wait state. Thread. Suspend() method will not go into wait state until . net determines that it is in a safe place to suspend it.
Suspend method puts a thread in a suspended state. Stop() method puts a thread in a dead state. suspended thread can be resumed to work by using the resume() method. Thread, once it is stopped, can't be resumed to work.
Sleep is used on a single thread and it suspends a thread for a period of time. Whereas suspend is deprecated.
Also check the Remarks from MSDN about Suspend:
Do not use the Suspend and Resume methods to synchronize the activities of threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while it holds locks during a security permission evaluation, other threads in the AppDomain might be blocked. If you suspend a thread while it is executing a class constructor, other threads in the AppDomain that attempt to use that class are blocked. Deadlocks can occur very easily.
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