1

Recently I came across an MSDN link which says that the ManualResetEventSlim class can be used for better performance when compared to ManualResetEvent class.

"In the .NET Framework 4, you can use the System.Threading.ManualResetEventSlim class for better performance when wait times are expected to be very short".

https://msdn.microsoft.com/en-us/library/5hbefs30%28v=vs.110%29.aspx

Please correct me if my understanding is wrong.

When WaitOne(1000) is called for 1 sec

  • the windows, apart from blocking the other threads from executing, makes the current thread to sleep for certain time and wakes up when it is notified.

  • Here the word blocking means that the thread sleeps for certain time until it is notified?

  • What does this sentence mean - "when wait times are expected to be very short"?

    Can somebody suggest any websites to understand the internal process of WaitOne

Community
  • 1
  • 1
  • 1
    In a multi-threaded environment with multiple threads really running concurrently (and not just context-switching on one core), the act of context-switching from one thread to another can be costly. A blocking wait, like with ManualResetEvent can provoke such a context-switch. ManualResetEventSlim on the other hand will do busy-waiting, meaning it will enter a tight loop waiting for a short while for the event to become signalled. Thus you don't get a context-switch. – Lasse V. Karlsen Jul 22 '15 at 16:21
  • The best place to start if you want to know how something is implemented in .NET, is [the actual source](http://referencesource.microsoft.com/#mscorlib/system/threading/waithandle.cs,4b231a1c8efbe5a7) which eventually leads us to [this](http://referencesource.microsoft.com/#mscorlib/system/threading/waithandle.cs,38951ac89a5d75ca), which unfortunately in this case means it's implemented by the CLR itself. But wait! [That's open source too now!](https://github.com/dotnet/coreclr/blob/master/src/vm/comwaithandle.cpp#L165) – James Thorpe Jul 22 '15 at 16:22

0 Answers0