1. Back To Blog

C# threading interview questions: - What is the difference between

"AutoResetEvent" and "ManualResetEvent" are threading concepts which help us to manage synchronization using events/ signals. For instance let's say you have two threads as shown in the figure. So by using these two concepts you can make one thread wait and when the other thread finishes processing he can signal the second thread to start from where he has halted.

C# threading

So you can create the object of "AutoResetEvent" and "ManualResetEvent" by the using the below code snippets. 

ManualResetEventobjAuto = newManualResetEvent(false);
AutoResetEventobjAuto = newAutoResetEvent(false);

If you want to make a thread wait , you can call

objAuto.WaitOne();

If you want to revoke it again, you can call

objAuto.Set();

If you see both these things they do one and the same thing, i.e. make a thread halt and then revoke them. Even the syntaxes are absolutely same, but with one big difference which is shown in the below figure.

When we use "AutoResetEvent" for every wait one we need a "Set" to revoke. In "ManualResetEvent" once we can the "Set" , all "WaitOne" will execute until we call "Close".

C# threading

Still confused watch this video

See for more stuffs on c# interview questions and answers

See following C# interview questions with answers tutorial :-

Click to view more from author's on C# and .NET Interview question

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social