Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen calling a class using BackgroundWorker nothing happens
    text
    copied!<p>This is my first post on this site so I apologize if I am not following protocol :)</p> <p>I have created a form in C#.net and trying to use a BackgroundWorker to call a class.</p> <p>I have a button for calling the class (named listener) using RunWorkerAsync however when debugging I can't see the class being called and it seems that the debugger steps over it. Here is my code:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Sockets; namespace McServer { public partial class app : Form { BackgroundWorker bgw = new BackgroundWorker(); public app() { InitializeComponent(); listener.UpdateLabel += UpdateLabelFromListener; bgw.WorkerReportsProgress = true; bgw.WorkerSupportsCancellation = true; bgw.DoWork += new DoWorkEventHandler(bw_DoWork); bgw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged); bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); } private void startBtn_Click(object sender, EventArgs e) //private void startBtn_Click(BackgroundWorker bw, EventArgs e) { if (bgw.IsBusy != true) { // Start the asynchronous operation. if (ipTxt.Text != "" &amp;&amp; portTxt.Text != "" &amp;&amp; dirTxt.Text != "") { listener t = new listener() { ip = ipTxt.Text, portID = portTxt.Text, path = dirTxt.Text }; //bw.DoWork(t); bgw.RunWorkerAsync(t); } else { MessageBox.Show("Fill in all fields first"); } } } private void cancelBtn_Click(object sender, EventArgs e) { if (bgw.WorkerSupportsCancellation == true) { bgw.CancelAsync(); } } private void bw_DoWork(object sender, DoWorkEventArgs e) { bgw = sender as BackgroundWorker; for (int i = 1; i &lt;= 10; i++) { if (bgw.CancellationPending == true) { e.Cancel = true; break; } else { System.Threading.Thread.Sleep(500); bgw.ReportProgress(i * 10); } } } private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { resultLabel.Text = (e.ProgressPercentage.ToString() + "%"); } private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled == true) { resultLabel.Text = "Canceled!"; } else if (e.Error != null) { resultLabel.Text = "Error: " + e.Error.Message; } else { resultLabel.Text = "Done!"; } } void UpdateLabelFromListener(string message) { this.Invoke((Action)(() =&gt; { label5.Text = message; })); } private void brwsBtn_Click(object sender, EventArgs e) { FolderBrowserDialog dir = new FolderBrowserDialog(); dir.ShowDialog(); dirTxt.Text = dir.SelectedPath; string path = dirTxt.Text; } </code></pre>
 

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