Threading with Background worker
Hello.
I'mt rying to tun a process in the back gorund using the background worker, but when the thread is comlpete it does not run the "RunWorkerCompleted" function do i need to call/invoke it somehow or should it run when the thread is complete?
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker bw = new BackgroundWorker();
int arg = (int)e.Argument;
e.Result = Engine(bw, arg, e);
if (bw.CancellationPending)
{
e.Cancel = true;
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled)
{
MessageBox.Show("Operation was canceled");
}
else if (e.Error != null)
{
string msg = string.Format("An error occurred: {0}", e.Error.Message);
MessageBox.Show(msg);
}
else
{
string msg = string.Format("Result = {0}", e.Result);
}
}
in addition if i try to call the progressChanged event the progress bar will not update, what em i doing wrong?
THANKS!!
|