Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would definitely avoid #3. Despite the fervor over using <code>Control.Invoke</code> to coordinate worker and UI threads it is often overused and is <em>usually</em> a suboptimal strategy at best. I much prefer #1 and #2 over #3. Here are the reasons why I tend to avoid #3.</p> <ul> <li>It tightly couples the UI and worker threads.</li> <li>The worker thread gets to dictate how much work the UI thread performs.</li> <li>The worker thread has to wait for the UI thread to respond before proceeding.</li> <li>It is an expensive operation.</li> </ul> <p>I know it may require some additional upfront effort on your part to get #1 or #2 going, but the end result will be better in the long run. </p> <p>As a corollary to my answer the <code>Control.Invoke</code> method tends to be overused when data needs to follow the opposite direction as well (from worker thread to UI thread as in the case of sending progress information to the UI). Sadly this is the method that <code>BackgroundWorker</code> uses internally with its <code>ReportProgress</code> method. It is <em>usually</em> better to have the UI thread poll a shared data structure for this information for some of the same reasons as above plus:</p> <ul> <li>The UI thread gets to dictate when and how often the update should take place.</li> <li>It puts the responsibility of updating the UI thread on the UI thread where it should belong anyway.</li> <li>There is no risk of the UI message pump being overrun as would be the case with the marshaling techniques initiated by the worker thread.</li> </ul> <p>However, with that said I am <em>not</em> suggesting that you abandon <code>BackgroundWorker</code> entirely. Just keep some of these points in mind.</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.
    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