Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It appears that you want to run Tasks 1 - 3 to execute <em>synchronously</em>. So, you might as well do:</p> <pre><code>Task1(); Task2(); Task3(); </code></pre> <p>If you want to offload the execution of these tasks to another thread, you can do:</p> <pre><code>static void RunTasks() { Task1(); Task2(); Task3(); } static void Main() { new Thread(RunTasks).Start(); } </code></pre> <p>If you really wanted each task to run on a separate <em>thread</em>, and wait for the previous task to finish, you can use the <a href="http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx" rel="nofollow"><strong><code>Thread.Join</code></strong></a> method.</p> <p><strong>EDIT</strong>:</p> <p>Since you really want to use wait-handles to accomplish this, take a look at the <a href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx" rel="nofollow"><strong><code>ManualResetEvent</code></strong></a> class.</p> <blockquote> <p>Notifies one or more waiting threads that an event has occurred.</p> </blockquote> <p>Call the <code>WaitOne</code> method on it to wait on the event, and the <code>Set</code> method to signal it.</p> <p>Example (horribly contrived code):</p> <pre><code>var afterT1Event = new ManualResetEvent(false); var afterT2Event = new ManualResetEvent(false); Thread t1 = new Thread(() =&gt; { Task1(); afterT1Event.Set(); }); Thread t2 = new Thread(() =&gt; { afterT1Event.WaitOne(); Task2(); afterT2Event.Set(); }); Thread t3 = new Thread(() =&gt; { afterT2Event.WaitOne(); Task3(); }); t1.Start(); t2.Start(); t3.Start(); </code></pre>
 

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