C# threading interview questions: - What is the difference between "AutoResetEvent" and "ManualResetEvent"?
"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.
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
If you want to revoke it again, you can call
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".
Still confused watch this video
See for more stuffs on c# interview questions and answers
Click to view more from author's on C# and .NET Interview question