Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exitContext used for on a WaitHandle.WaitOne method

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

like image 965
Bigtoe Avatar asked Apr 16 '09 10:04

Bigtoe


People also ask

What does WaitOne do?

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.

How to use WaitHandle in c#?

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.


1 Answers

I can't claim credit (hence wiki) but there is a good answer here.

like image 172
Marc Gravell Avatar answered Sep 19 '22 21:09

Marc Gravell