Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (general.backgroundWorker1.CancellationPending)
- {
- return;
- }
- private void button4_Click(object sender, EventArgs e) //button invokes heavy function
- {
- if (!backgroundWorker1.IsBusy)
- backgroundWorker1.RunWorkerAsync();
- }
- private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
- {
- heavyFunction(this);
- if (backgroundWorker1.CancellationPending)
- {
- e.Cancel = true;
- return;
- }
- }
- private void backgroundWorker1_RunWorkerCompleted_1(object sender, RunWorkerCompletedEventArgs e)
- {
- if (e.Cancelled)
- {
- statusLabel.Text = "Status: cancelled";
- }
- else if (e.Error != null)
- {
- statusLabel.Text = "ERROR!";
- }
- else
- {
- some code;
- }
- }
- private void cancelSDoutLoop_Click(object sender, EventArgs e)
- {
- if (backgroundWorker1.IsBusy)
- {
- backgroundWorker1.CancelAsync();
- }
- }
- Delay(TimeSpan)
- Delay(TimeSpan, CancellationToken)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement