System.ComponentModel; BackgroundWorker bgw = new BackgroundWorker();
bgw.WorderSupportsCancellation; //whether supports cancellation or not bgw.WorkerReportsProgress; //whether reports progress or not bgw.ReportProgress(20); //report pregress 20% bgw.CancelAsync; //calcel it
using System.Threading.Thread; void dotButton_Click(object sender, EventArgs e) { BackgroundWorker bgw = sender as BackgroundWorker; for (int i = 1; i < 50; i++) { if (bgw.CancellationPending == true) { break; } Sleep(1000); int k = i * 2; bgw.ReportProgress(k); } }