BackgroundWorker Example - C#

BackgroundWorker Example - C#

code snippet

c#
private readonly BackgroundWorker worker = new BackgroundWorker();

public Form1()
{
      InitializeComponent();
      worker.DoWork += worker_DoWork;
      worker.RunWorkerCompleted += worker_RunWorkerCompleted;
}

private void button1_Click(object sender, EventArgs e)
{
         string _param = "your parameter";
          worker.RunWorkerAsync(_param );
}

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
      string _param = (string)e.Argument;
      // update label
      label.Invoke((MethodInvoker)delegate
      {
             label.Text = "executing...";
      });
      // your custom actions
      e.Result = "pass to complete";
}

private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
       string result = (string)e.Result;
       // your custom actions
}

"The measure of who we are is what we do with what we have"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.