一个Freamwork GUI程序,有一个进度条,两个按钮。程序主要展示了BackgroundWorker类的使用。
异步编程简单示例
BackgroundWorker对象的常用事件
- bgWorker.DoWork += DoWork_Handler;
- bgWorker.ProgressChanged += ProgressChanged_Handler;
- bgWorker.RunWorkerCompleted += RunWorkerCompleted_Handler;
BackgroundWorker对象的常用属性
- bgWorker.WorkerReportsProgress = true;
- bgWorker.WorkerSupportsCancellation = true;
- bgWorker.IsBusy
- worker.CancellationPending
BackgroundWorker对象的常用方法(异步方法名命名约定以Async结尾)
- bgWorker.RunWorkerAsync();
- worker.ReportProgress(i * 10);
- bgWorker.CancelAsync();
1 | |