Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should wrap all of the work in to a single background worker that creates the database. You could kick of a sequence of methods for the steps of the create database method and check the result of each one to determine if you should cancel. As each step (or method) succeeds, you can report progress back on the callback event (BW_ProgressChanged). In the progress changed event handler you want to update the txtProgress control there. If you start setting properties on UI controls in a background thread you will start running in to cross-threading issues.</p> <pre><code>using System.ComponentModel; using System.Threading; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, System.EventArgs e) { // Start the BackgroundWorker. backgroundWorker1.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { for (int i = 1; i &lt;= 100; i++) { // Wait 100 milliseconds. Thread.Sleep(100); // Report progress. backgroundWorker1.ReportProgress(i); } } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Change the value of the ProgressBar to the BackgroundWorker progress. progressBar1.Value = e.ProgressPercentage; // Set the text. this.Text = e.ProgressPercentage.ToString(); } } } </code></pre> <p>The BackgroundWorker object is the traditional way to do this with WinForms, but have you had a look at <a href="http://msdn.microsoft.com/en-us/library/dd321424.aspx" rel="nofollow">Task</a>? The Task is .net 4.0 framework specific so it may not apply depending on the version of the framework you are targeting.</p>
 

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