The MSDN documentation for ManualResetEventSlim
states
You can use this class for better performance than
ManualResetEvent
when wait times are expected to be very short.
How long is "very short"? At what point will the benefit of using a kernel object with a ManualResetEvent
outweigh the overhead of instantiating it?
This is what I found and would love for someone else to validate this, but this is what I found while reading the Reference Source for ManualResetEventSlim
ManualResetEventSlim
It is attempting to just sleep and yield based on the number of processors and doing extremely short sleeps -- 1ms or 0ms depending on its current spin index. If it still hasn't been enough time, it will then revert to using Monitor.Wait
using a new updated version of the timeout that was originally passed in.
Passing in 0 for Thread.Sleep relieves its time slice.
ManualResetEvent
It uses WaitHandle
and calls native methods to handle waiting for the specified time. Unfortunately, I am unable to see what it is doing.
My Conclusion
"Very Short" means just a few milliseconds.
EDIT: I just found these which have lots of information:
How long is a single spin in ManualResetEventSlim
http://social.msdn.microsoft.com/Forums/vstudio/en-US/9ce62320-68fe-4d07-8576-f30a0325a68c/when-to-use-manualreseteventslim?forum=parallelextensions
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