???????????
????????й??????????????????????????????????????BackgroundWorker????к???????
????_demoBGWorker.WorkerSupportsCancellation = true;
??????WorkerReportsProgress?????????????????????????????????? WorkerSupportsCancellation????? true??????????BGWorker_DoWork?????н????????? for ????? Thread.Sleep(600)??????????
????bgWorker.ReportProgress(i?? message);
????Thread.Sleep(600);
????//??????????????????????????????????????
????if (bgWorker.CancellationPending == true)
????{
????e.Cancel = true;
????break;
????}
?????????????????????????????????????????????????????????????????
????_demoBGWorker.CancelAsync();
?????????????????????????????????????
??????????
????????????????з?????????????????????а?????????????????????????У????????????????????????????????
????_demoBGWorker.RunWorkerCompleted += BGWorker_RunWorkerCompleted;
????private void BGWorker_RunWorkerCompleted(object sender?? RunWorkerCompletedEventArgs e)
????{
????//????????????????????????
????if (e.Cancelled)
????{
????this.Close();
????}
????//????????????????????????????
????this.btnCancel.Enabled = false;
????//????????е????????????????????д????
????if (e.Error != null)
????{
????Type errorType = e.Error.GetType();
????switch (errorType.Name)
????{
????case "ArgumentNullException":
????case "MyException":
????//do something.
????break;
????default:
????//do something.
????break;
????}
????}
????//???????????e.Result
????//use it do something.
????}
????RunWorkerCompleted ??????????????DoWork ??????????????????á?????????????????Щ??????????????????????????????????????????????
???????????????? e.Result?????????BGWorker_DoWork?????????? e.Result??????磺
????e.Result = sum;
???????BackgroundWorker ????????????ü???????????????????????????