Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You do not need to run forms in separate threads. You can just call <code>s.Show()</code> on multiple forms normally. They will not block each other.</p> <p>Of course, if you’re doing <em>something else</em>, like some sort of calculation or other task that takes a long while, then you should run <em>that</em> in a separate thread, but not the form.</p> <p>Here is a bit of code that will let you create a progress bar that shows progress for a long process. Notice that every time to access the form from inside the thread, you have to use <code>.Invoke()</code>, which actually schedules that invocation to run on the GUI thread when it’s ready.</p> <pre><code>public void StartLongProcess() { // Create and show the form with the progress bar var progressForm = new Subform(); progressForm.Show(); bool interrupt = false; // Run the calculation in a separate thread var thread = new Thread(() =&gt; { // Do some calculation, presumably in some sort of loop... while ( ... ) { // Every time you want to update the progress bar: progressForm.Invoke(new Action( () =&gt; { progressForm.ProgressBar.Value = ...; })); // If you’re ready to cancel the calculation: if (interrupt) break; } // The calculation is finished — close the progress form progressForm.Invoke(new Action(() =&gt; { progressForm.Close(); })); }); thread.Start(); // Allow the user to cancel the calculation with a Cancel button progressForm.CancelButton.Click += (s, e) =&gt; { interrupt = true; }; } </code></pre>
    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. 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