Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT: Okay, now we have more information and know that the question isn't <em>really</em> about a user interface, it's easy:</p> <pre><code>List&lt;Task&gt; listOfTasks = GetListOfTasks() List&lt;Thread&gt; threads = new List&lt;Thread&gt;(); foreach(Task task in Tasks) { DoSomeWork work = new DoSomeWork(task); Thread workerThread = new Thread(work.CompleteTask); workerThread.Start(); threads.Add(workerThread); } // Now all the threads have started, Join on them in turn to wait // for them to finish. DON'T DO THIS IN A UI THREAD IN A NORMAL APP. foreach (Thread thread in threads) { thread.Join(); } </code></pre> <p>Of course, using the TPL's <code>WaitForAll</code> <em>is</em> a better idea than this - if you can use it, do so. But if you're using plain threads, <code>Join</code> is fine.</p> <hr> <p>EDIT: I've been assuming you're writing a Windows Forms application, based on the Form1_Load method. It would be helpful if you could give more context in the question.</p> <p>Well, your threads are unlikely to have all finished immediately after you've started them all... and you shouldn't block the UI thread <em>waiting</em> for them to finish, as your UI will hang.</p> <p>Instead, you should make each <code>DoSomeWork</code> task call back into the UI when it's finished. Either <code>DoSomeWork</code> could have an event you could add a handler to, or you could pass a completion handler delegate into the constructor, or perhaps it knows about the form directly and can call back itself - it depends on what it's doing really.</p> <p>Anyway, when the task has effectively finished, you can post back to the UI thread using <code>Control.BeginInvoke</code>. The form could keep track of how many tasks has finished, so that if it needs to do something when <em>everything</em> has finished, it can do so.</p> <p>If this doesn't help, please give more information about what you want to happen when all the tasks have finished, and what those tasks are doing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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