In the example below, I use the ReportProgress functionality of the BackgroundWorker:
void MyMethod()
{
if (!File.Exists)
{
bw.ReportProgress(0, "Error");
}
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
this.MyMethod1();
this.MyMethod2();
this.MyMethod3();
}
private void bw_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
string error = e.UserState as String;
if (!string.IsNullOrEmpty(error)
{
// stop BackgrowndWorker
}
}
In every MyMethod()
i check something and do ReportProgress.
If there are possibilities to correctly stop BackgroundWorker in my case?
Need i to change the way of my code architecture?