Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're talking just <code>BackgroundWorker</code>, then you'd have to create 5 backgrounds workers. If you simply want 5 threads, you can create those yourself. The issue then becomes how to communicate progress and completion back to the UI thread. With <code>BackgroundWorker</code>, you do that with <code>WorkerReportsProgress</code>/<code>ReportProgress</code> and the Completed event. Now, you <em>could</em> certain just uses the <code>BackgroundWorker</code> <code>DoWork</code> handler to spawn the threads you want and manage communication of data from those threads back to the UI thread via <code>ReportProgress</code> and <code>Completed</code>.</p> <p>For example:</p> <pre><code>private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Thread thread1 = new Thread(ThreadOneEntry); thread1.Start(); Thread thread2 = new Thread(ThreadTwoEntry); thread2.Start(); Thread thread3 = new Thread(ThreadThreeEntry); thread3.Start(); Thread thread4 = new Thread(ThreadFourEntry); thread4.Start(); Thread thread5 = new Thread(ThreadFiveEntry); thread5.Start(); thread1.Join(); thread2.Join(); thread3.Join(); thread4.Join(); thread5.Join(); // do something to report results from threads1-5 } </code></pre> <p>This, of course, doesn't do anything with progress--that would be very application specific and anything I come up with is likely to be entirely different than what you would do and be of no help. But, each thread could report progress back through the <code>BackgroundWorker.ReportProgress</code> method directly--you'd just have to give each thread the <code>BackgroundWorker</code> instances or a delegate to the <code>ReportProgress</code> method.</p> <p>it's also not a terribly effective use of a thread for the background worker, it just goes into a wait state waiting for other threads, the <code>DoWork</code> event handler could just as easily do some of the work that one of the other thread entries would have...</p> <p>I'd recommend using <code>Task&lt;T&gt;</code> instead of <code>Thread</code> if you are on .NET 3.5 or better and you want to perform background work that has results. Plus, spinning up your own threads does no load-balancing. Task through the TPL does its own load balancing...</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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