Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use BackgroundWorker in winform c#
    primarykey
    data
    text
    <p>i'm new to winform and i can't figure out how to use the BackgroundWorker.</p> <p>basically what i'm trying to do is this:</p> <p>i have 1 form with 2 buttons: "Import" and "Exit" . when calling ImporButton_Click all it does is creates an HttpListener and listen to a given URL. ExitButton_Click closes the form.</p> <p>the problem is when i press "Import" the form get stuck and it's in "not responding" status until someone is calling the listener and free it.</p> <p>i'm trying to under stand how BackgroundWorker can help me to overcome that "stuck" problem. i don't understand how to invoke the backgroundWorker1_DoWork method</p> <p>Here is my code so far:</p> <pre><code>//Program.cs static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ConfigurationForm()); } } //ConfigurationForm.cs public partial class ConfigurationForm : Form { public ConfigurationForm() { InitializeComponent(); UrlTextBox.Text = @"enter URL here"; } private void ImporButton_Click(object sender, EventArgs e) { try { String urlToListen = UrlTextBox.Text; //Invoke MyListener MyListener.StartListen(urlToListen); //assume this is implemented } catch (Exception exception) { string errorMsg = String.Format("An exception occured = {0}", exception); MessageBox.Show(errorMsg); } } private void ExitButton_Click(object sender, EventArgs e) { this.Close(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { } } </code></pre> <p>so, what now ? how do i invoke the backgroundWorker1_DoWork ???</p> <p>10x to anyone who can help </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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