i'm new to winform and i can't figure out how to use the BackgroundWorker.
basically what i'm trying to do is this:
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.
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.
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
Here is my code so far:
//Program.cs
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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)
{
}
}
so, what now ? how do i invoke the backgroundWorker1_DoWork ???
10x to anyone who can help