Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is standard behavior for any Windows GUI application, screen updates don't happen until the UI thread goes idle so that Windows can deliver the Paint event. One of the absolute worst things you could do is calling Application.DoEvents(). Yes, that will deliver the Paint event. But it also allows your user to close the form. That produces a Big Kaboom when the control you are trying to update is suddenly not there anymore. Your loop is still running, but the form isn't there anymore.</p> <p>What you must have noticed is that the progress bar actually updated but the CheckedListBox did not. That's because ProgressBar often is used to show progress when the code is in a loop, so it makes sure that when you change the Value property, it immediately paints itself without waiting for Windows to tell it that it needs to be repainted. Dirty trick, very confusing.</p> <p>But you can take advantage of that trick as well, it is easy. Modify your code like this:</p> <pre><code>for (int i = 0; i &lt; 10; i++) { SOME_FUNCTION(); progressBar.Value++; checkListBoxItems.SetItemCheckState(i, CheckState.Checked); checkListBoxItems.Update(); } </code></pre> <p>The Update() method means "paint yourself when necessary". It is, you changed the check state of an item. Never does the Big Kaboom thingy on you, the user can't suddenly make the control disappear.</p> <p>If SOME_FUNCTION() takes a long time, like more than 10 x 0.3 seconds or so, then you should start thinking about using threads.</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. 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