Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. if (general.backgroundWorker1.CancellationPending)
  2. {
  3. return;
  4. }
  5.  
  6. private void button4_Click(object sender, EventArgs e) //button invokes heavy function
  7. {
  8. if (!backgroundWorker1.IsBusy)
  9. backgroundWorker1.RunWorkerAsync();
  10. }
  11.  
  12. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  13. {
  14. heavyFunction(this);
  15. if (backgroundWorker1.CancellationPending)
  16. {
  17. e.Cancel = true;
  18. return;
  19. }
  20. }
  21.  
  22. private void backgroundWorker1_RunWorkerCompleted_1(object sender, RunWorkerCompletedEventArgs e)
  23. {
  24. if (e.Cancelled)
  25. {
  26. statusLabel.Text = "Status: cancelled";
  27. }
  28. else if (e.Error != null)
  29. {
  30. statusLabel.Text = "ERROR!";
  31. }
  32. else
  33. {
  34. some code;
  35. }
  36. }
  37.  
  38. private void cancelSDoutLoop_Click(object sender, EventArgs e)
  39. {
  40. if (backgroundWorker1.IsBusy)
  41. {
  42. backgroundWorker1.CancelAsync();
  43. }
  44. }
  45.  
  46. Delay(TimeSpan)
  47.  
  48. Delay(TimeSpan, CancellationToken)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement