Skip to content

Instantly share code, notes, and snippets.

@kaskavalci
Created September 26, 2015 10:40
Show Gist options
  • Save kaskavalci/8856d09f6b279c5cc9fd to your computer and use it in GitHub Desktop.
Save kaskavalci/8856d09f6b279c5cc9fd to your computer and use it in GitHub Desktop.
private ManualResetEvent mre = new ManualResetEvent(false);
void startBW() {
BW = new BW(); //BW is BackgroundWorker class
BW.RunWorkerCompleted += BW_RunWorkerCompleted;
BW.ProgressChanged += BW_ProgressChanged;
BW.RunWorkerAsync();
//wait until it finishes
mre.WaitOne();
}
void BW_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//if cancellation is pending in this thread, notify the child BW
if (CancellationPending)
{
BW.CancelAsync();
}
}
void BW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//when everyting is set, raise flag so that execution will continue.
mre.Set();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment