近来在学习Eugene Agafonov编写的《C#多线程编程实战》(译),做些笔记也顺便分享一下^-^
本实例演示了另一种异步编程的方式,即使用BackgroundWorker组件。借助于该对象,可以将异步代码组织为一系列事件及事件处理器
using System;
using System.Threading;
using System.ComponentModel;
namespace 使用BackgroundWorker组件
{
class Program
{
static void Main(string[] args)
{
var bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
bw.DoWork += Worker_DoWork;
bw.ProgressChanged += Worker_ProgressChanged;
bw.RunWorkerCompleted += Worker_Completed;
bw.RunWorkerAsync();
Console.WriteLine("Press C to cancel work");
do
{
if (Console.Rea