Example
System.Threading.AutoResetEvent e = new System.Threading.AutoResetEvent(false); bool b = e.WaitOne(1000, false);
I've done a lot of multi threaded development in my time and have always wondered what the use of the that method was for. The second boolean parameter on the WaitOne is called exitContext. MS Help states "true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false."
Anyone any idea what this means? Is it something I should be worried about?
Kind Regards Noel
WaitOne(TimeSpan, Boolean) Blocks the current thread until the current instance receives a signal, using a TimeSpan to specify the time interval and specifying whether to exit the synchronization domain before the wait.
static WaitHandle[] waitHandles = new WaitHandle[] { new AutoResetEvent(false), new AutoResetEvent(false) }; // Define a random number generator for testing. static Random r = new Random(); static void Main() { // Queue up two tasks on two different threads; // wait until all tasks are completed.
I can't claim credit (hence wiki) but there is a good answer here.
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