Created
September 26, 2015 10:40
-
-
Save kaskavalci/8856d09f6b279c5cc9fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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