Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between suspend and sleep in Thread in c#

Tags:

c#

Thread.Sleep(5000);
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds);
Thread.suspend(5000);
Console.WriteLine(stopwatch.ElapsedMilliseconds);
like image 857
kannan ganesh Avatar asked Oct 29 '15 11:10

kannan ganesh


People also ask

What is the difference between sleep () and suspend () method?

Sleep is used on a single thread and it suspends a thread for a period of time. Whereas suspend is deprecated.

What is difference between sleep () and wait ()?

Wait() method releases lock during Synchronization. Sleep() method does not release the lock on object during Synchronization.

What is the difference between sleep () and suspend () methods in VB net?

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.

What is the difference between suspending and stopping a thread?

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.


Video Answer


1 Answers

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.

like image 92
Rahul Tripathi Avatar answered Oct 30 '22 17:10

Rahul Tripathi