To make a choice between ManualResetEvent or Thread.Sleep() To make a choice between ManualResetEvent or Thread.Sleep() multithreading multithreading

To make a choice between ManualResetEvent or Thread.Sleep()


Out of curiosity, why ManualResetEvent and not AutoResetEvent? Either way, go with the OS primitive over a sleep-check-sleep approach.

You could also use a Monitor lock (either explicitly through Monitor.Enter and Monitor.Exit, or through a lock block), but the approach should be based upon what you're actually doing; if it's a scenario of "there's only one of these things and I need exclusive access", then use a Monitor lock. If it's "I need to wait until the other thread finishes for reasons other than resource access", then use an AutoResetEvent or ManualResetEvent.

The suggestions to use Thread.Join are good if (and only if)

  1. You have access to the other Thread object
  2. You don't want to execute until the other thread terminates.

If either isn't true (you don't have access, or the other thread won't terminate, it will just signal an "all clear") then Thread.Join isn't viable.

The worst option is

while(!JobCompleted);

As that will tie up the processor with needless checks of the variable without any pause in between them. Yes, it will block your thread until the operation completes, but you'll max out CPU usage (or at least a single core's worth).


The event makes more efficient use of the processors- you're not having to wake the parent thread up to poll. The kernel will wake you up when the event fires.


If you have access to the original Thread object, or can get that access, you're best off using Thread.Join().

Edit: Also, if this is taking place in a GUI like WinForms or WPF, you may want to consider using BackgroundWorker