C#使用BackgroundWorker实现多线程
BackgroundWorker的对象定义:
this.backgroundWorker.WorkerSupportsCancellation = true; this.backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.DoWork); this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.RunWokerCompeted); private System.ComponentModel.BackgroundWorker backgroundWorker;
DoWork方法里包含了需要单开线程索要执行的操作动作。
该方法在BackgroundWorker.RunWorkerAsync()被调用时发生。