Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use a <a href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.aspx" rel="nofollow noreferrer"><code>WaitHandle</code></a></p> <hr> <p>Here's an example:</p> <pre><code>using System; using System.Threading; class ThreadSleeper { int seconds; AutoResetEvent napDone = new AutoResetEvent(false); private ThreadSleeper(int seconds) { this.seconds = seconds; } public void Nap() { Console.WriteLine("Napping {0} seconds", seconds); Thread.Sleep(seconds * 1000); Console.WriteLine("{0} second nap finished", seconds); napDone.Set(); } public static WaitHandle DoSleep(int seconds) { ThreadSleeper ts = new ThreadSleeper(seconds); Thread thread = new Thread(new ThreadStart(ts.Nap)); thread.Start(); return(ts.napDone); } } public class OperationsThreadsWaitingwithWaitHandle { public static void Main() { WaitHandle[] waits = new WaitHandle[2]; waits[0] = ThreadSleeper.DoSleep(8); waits[1] = ThreadSleeper.DoSleep(4); Console.WriteLine("Waiting for threads to finish"); WaitHandle.WaitAll(waits); Console.WriteLine("Threads finished"); } } </code></pre> <hr> <p><strong>Links to check out</strong>:</p> <ul> <li><a href="http://www.java2s.com/Code/CSharp/Thread/ThreadsWaitingwithWaitHandle.htm" rel="nofollow noreferrer">Threads:Waiting with WaitHandle</a></li> <li><a href="http://www.yoda.arachsys.com/csharp/threads/waithandles.shtml" rel="nofollow noreferrer">Jon Skeet's post</a></li> <li><a href="https://stackoverflow.com/questions/990970/difference-between-barrier-in-c-4-0-and-waithandle-in-c-3-0">Difference between Barrier in C# 4.0 and WaitHandle in C# 3.0?</a></li> <li><a href="http://bojordan.com/log/?p=258" rel="nofollow noreferrer">Novice C# threading: WaitHandles</a></li> <li><a href="http://www.codeproject.com/KB/recipes/WaitHandleExceptions.aspx?display=Print" rel="nofollow noreferrer">WaitHandle Exceptions and Work Arounds</a></li> <li><a href="http://ondotnet.com/pub/a/dotnet/2001/08/06/csharp.html?page=4&amp;x-maxdepth=0" rel="nofollow noreferrer">Multithreading with C#</a></li> <li><a href="http://www.developerfusion.com/article/5184/multithreading-in-vbnet/3/" rel="nofollow noreferrer">WaitHandle, AutoResetEvent and ManualResetEvent Classes in VB.Net</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload