Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm assuming with your <code>.InvokeRequired</code>/<code>Invoke(...)</code> code that you are using WinForms and not WPF.</p> <p><code>BackgroundWorker</code> will call the <code>ProgressChanged</code> and <code>RunWorkerCompleted</code> events on the main thread (assuming you created the worker on that thread). If you are adding items to your <code>ListBox</code> on either one of these events, you should not require the <code>Invoke()</code>.</p> <p>If you are going to be rapidly adding items to the <code>ListBox.Items</code> collection, I suggest you use <code>ListBox.BeginUpdate()</code> and <code>ListBox.EndUpdate()</code> which will temporarily suspend redrawing of the <code>ListBox</code> while you add items. This is useful when you are adding hundreds or thousands of items to the <code>ListBox</code> in mere seconds.</p> <p>For example:</p> <pre><code>void ReloadListBox() { listBox.BeginUpdate(); // Suspend redrawing listBox.Items.Clear(); // Remove all existing items first backgroundWorker.RunWorkerAsync(); // Asynchronous generate new items } void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Report a new list item in e.UserState. var newItem = e.UserState; listBox.Items.Add(newItem); } void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // Alternatively, return a list of items in e.Result. var items = e.Result; listBox.Items.AddRange(items); listBox.EndUpdate(); // Resume redrawing and update } </code></pre>
    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. VO
      singulars
      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