学习了多线程BackgroundWorker,以此记录。

 此案例功能:

     实现用BackgroundWorker处理进度条,可以开始,暂停,继续,清空。

 BackgroundWorker说明:   摘抄自---http://msdn.microsoft.com

      BackgroundWorker 类允许您在单独的专用线程上运行操作。耗时的操作(如下载和数据库事务)在长时间运行时可能会导致用户界面 (UI) 似乎处于停止响应状态。如果您需要能进行响应的用户界面,而且面临与这类操作相关的长时间延迟,则可以使用 BackgroundWorker 类方便地解决问题。若要在后台执行耗时的操作,请创建一个 BackgroundWorker,侦听那些报告操作进度并在操作完成时发出信号的事件。可以通过编程方式创建 BackgroundWorker,也可以将它从“工具箱”的“组件”选项卡中拖到窗体上。如果在 Windows 窗体设计器中创建 BackgroundWorker,则它会出现在组件栏中,而且它的属性会显示在“属性”窗口中。若要设置后台操作,请为 DoWork 事件添加一个事件处理程序。在此事件处理程序中调用耗时的操作。若要启动该操作,请调用 RunWorkerAsync。若要收到进度更新通知,请对 ProgressChanged 事件进行处理。若要在操作完成时收到通知,请对 RunWorkerCompleted 事件进行处理。

     您必须非常小心,确保在 DoWork 事件处理程序中不操作任何用户界面对象。而应该通过 ProgressChanged 和 RunWorkerCompleted 事件与用户界面进行通信。

     BackgroundWorker 事件不跨 AppDomain 边界进行封送处理。请不要使用 BackgroundWorker 组件在多个 AppDomain 中执行多线程操作。如果后台操作需要参数,请在调用 RunWorkerAsync 时给出参数。在 DoWork 事件处理程序内部,可以从 DoWorkEventArgs..::.Argument 属性中提取该参数。

 

BackgroundWorker学习(转载)_sedBackgroundWorker学习(转载)_多线程_02界面Code
BackgroundWorker学习(转载)_i++_03namespace WindowsApplication1
BackgroundWorker学习(转载)_i++_04BackgroundWorker学习(转载)_事件处理_05
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07    
partial class Form1
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09    
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
/**//// <summary>
BackgroundWorker学习(转载)_事件处理_07        
/// Required designer variable.
BackgroundWorker学习(转载)_多线程_14        
/// </summary>

BackgroundWorker学习(转载)_事件处理_07        private System.ComponentModel.IContainer components = null;
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
/**//// <summary>
BackgroundWorker学习(转载)_事件处理_07        
/// Clean up any resources being used.
BackgroundWorker学习(转载)_事件处理_07        
/// </summary>
BackgroundWorker学习(转载)_多线程_14        
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

BackgroundWorker学习(转载)_事件处理_07        protected override void Dispose(bool disposing)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            
if (disposing && (components != null))
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09            
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                components.Dispose();
BackgroundWorker学习(转载)_多线程_14            }

BackgroundWorker学习(转载)_事件处理_07            
base.Dispose(disposing);
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_09BackgroundWorker学习(转载)_多线程_08        
Windows Form Designer generated code#region Windows Form Designer generated code
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
/**//// <summary>
BackgroundWorker学习(转载)_事件处理_07        
/// Required method for Designer support - do not modify
BackgroundWorker学习(转载)_事件处理_07        
/// the contents of this method with the code editor.
BackgroundWorker学习(转载)_多线程_14        
/// </summary>

BackgroundWorker学习(转载)_事件处理_07        private void InitializeComponent()
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
BackgroundWorker学习(转载)_事件处理_07            
this.colorDialog2 = new System.Windows.Forms.ColorDialog();
BackgroundWorker学习(转载)_事件处理_07            
this.progressBar1 = new System.Windows.Forms.ProgressBar();
BackgroundWorker学习(转载)_事件处理_07            
this.button1 = new System.Windows.Forms.Button();
BackgroundWorker学习(转载)_事件处理_07            
this.button2 = new System.Windows.Forms.Button();
BackgroundWorker学习(转载)_事件处理_07            
this.button3 = new System.Windows.Forms.Button();
BackgroundWorker学习(转载)_事件处理_07            
this.textBox2 = new System.Windows.Forms.TextBox();
BackgroundWorker学习(转载)_事件处理_07            
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
BackgroundWorker学习(转载)_事件处理_07            
this.label3 = new System.Windows.Forms.Label();
BackgroundWorker学习(转载)_事件处理_07            
this.label1 = new System.Windows.Forms.Label();
BackgroundWorker学习(转载)_事件处理_07            
this.button4 = new System.Windows.Forms.Button();
BackgroundWorker学习(转载)_事件处理_07            
this.SuspendLayout();
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// progressBar1
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.progressBar1.Location = new System.Drawing.Point(2785);
BackgroundWorker学习(转载)_事件处理_07            
this.progressBar1.Name = "progressBar1";
BackgroundWorker学习(转载)_事件处理_07            
this.progressBar1.Size = new System.Drawing.Size(21823);
BackgroundWorker学习(转载)_事件处理_07            
this.progressBar1.TabIndex = 0;
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// button1
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.button1.Location = new System.Drawing.Point(12222);
BackgroundWorker学习(转载)_事件处理_07            
this.button1.Name = "button1";
BackgroundWorker学习(转载)_事件处理_07            
this.button1.Size = new System.Drawing.Size(5423);
BackgroundWorker学习(转载)_事件处理_07            
this.button1.TabIndex = 1;
BackgroundWorker学习(转载)_事件处理_07            
this.button1.Text = "Execute ";
BackgroundWorker学习(转载)_事件处理_07            
this.button1.UseVisualStyleBackColor = true;
BackgroundWorker学习(转载)_事件处理_07            
this.button1.Click += new System.EventHandler(this.button1_Click);
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// button2
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.button2.Location = new System.Drawing.Point(72222);
BackgroundWorker学习(转载)_事件处理_07            
this.button2.Name = "button2";
BackgroundWorker学习(转载)_事件处理_07            
this.button2.Size = new System.Drawing.Size(5323);
BackgroundWorker学习(转载)_事件处理_07            
this.button2.TabIndex = 2;
BackgroundWorker学习(转载)_事件处理_07            
this.button2.Text = "Cancel";
BackgroundWorker学习(转载)_事件处理_07            
this.button2.UseVisualStyleBackColor = true;
BackgroundWorker学习(转载)_事件处理_07            
this.button2.Click += new System.EventHandler(this.button2_Click);
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// button3
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.button3.Location = new System.Drawing.Point(131222);
BackgroundWorker学习(转载)_事件处理_07            
this.button3.Name = "button3";
BackgroundWorker学习(转载)_事件处理_07            
this.button3.Size = new System.Drawing.Size(5723);
BackgroundWorker学习(转载)_事件处理_07            
this.button3.TabIndex = 3;
BackgroundWorker学习(转载)_事件处理_07            
this.button3.Text = "Continue ";
BackgroundWorker学习(转载)_事件处理_07            
this.button3.UseVisualStyleBackColor = true;
BackgroundWorker学习(转载)_事件处理_07            
this.button3.Click += new System.EventHandler(this.button3_Click);
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// textBox2
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.textBox2.Location = new System.Drawing.Point(145124);
BackgroundWorker学习(转载)_事件处理_07            
this.textBox2.Name = "textBox2";
BackgroundWorker学习(转载)_事件处理_07            
this.textBox2.Size = new System.Drawing.Size(10020);
BackgroundWorker学习(转载)_事件处理_07            
this.textBox2.TabIndex = 5;
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// backgroundWorker1
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.backgroundWorker1.WorkerReportsProgress = true;
BackgroundWorker学习(转载)_事件处理_07            
this.backgroundWorker1.WorkerSupportsCancellation = true;
BackgroundWorker学习(转载)_事件处理_07            
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
BackgroundWorker学习(转载)_事件处理_07            
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
BackgroundWorker学习(转载)_事件处理_07            
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// label3
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.label3.AutoSize = true;
BackgroundWorker学习(转载)_事件处理_07            
this.label3.Location = new System.Drawing.Point(33175);
BackgroundWorker学习(转载)_事件处理_07            
this.label3.Name = "label3";
BackgroundWorker学习(转载)_事件处理_07            
this.label3.Size = new System.Drawing.Size(5413);
BackgroundWorker学习(转载)_事件处理_07            
this.label3.TabIndex = 6;
BackgroundWorker学习(转载)_事件处理_07            
this.label3.Text = "UserState";
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// label1
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.label1.AutoSize = true;
BackgroundWorker学习(转载)_事件处理_07            
this.label1.Location = new System.Drawing.Point(24127);
BackgroundWorker学习(转载)_事件处理_07            
this.label1.Name = "label1";
BackgroundWorker学习(转载)_事件处理_07            
this.label1.Size = new System.Drawing.Size(10913);
BackgroundWorker学习(转载)_事件处理_07            
this.label1.TabIndex = 7;
BackgroundWorker学习(转载)_事件处理_07            
this.label1.Text = "Please input  number:";
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// button4
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.button4.Location = new System.Drawing.Point(194222);
BackgroundWorker学习(转载)_事件处理_07            
this.button4.Name = "button4";
BackgroundWorker学习(转载)_事件处理_07            
this.button4.Size = new System.Drawing.Size(6123);
BackgroundWorker学习(转载)_事件处理_07            
this.button4.TabIndex = 8;
BackgroundWorker学习(转载)_事件处理_07            
this.button4.Text = "Clear";
BackgroundWorker学习(转载)_事件处理_07            
this.button4.UseVisualStyleBackColor = true;
BackgroundWorker学习(转载)_事件处理_07            
this.button4.Click += new System.EventHandler(this.button4_Click);
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07            
// Form1
BackgroundWorker学习(转载)_事件处理_07            
// 
BackgroundWorker学习(转载)_事件处理_07
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
BackgroundWorker学习(转载)_事件处理_07            
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
BackgroundWorker学习(转载)_事件处理_07            
this.ClientSize = new System.Drawing.Size(292273);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.button4);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.label1);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.label3);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.textBox2);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.button3);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.button2);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.button1);
BackgroundWorker学习(转载)_事件处理_07            
this.Controls.Add(this.progressBar1);
BackgroundWorker学习(转载)_事件处理_07            
this.Name = "Form1";
BackgroundWorker学习(转载)_事件处理_07            
this.Text = "Form1";
BackgroundWorker学习(转载)_事件处理_07            
this.ResumeLayout(false);
BackgroundWorker学习(转载)_事件处理_07            
this.PerformLayout();
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14        
#endregion

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.ColorDialog colorDialog1;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.ColorDialog colorDialog2;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.ProgressBar progressBar1;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.Button button1;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.Button button2;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.Button button3;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.TextBox textBox2;
BackgroundWorker学习(转载)_事件处理_07        
private System.ComponentModel.BackgroundWorker backgroundWorker1;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.Label label3;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.Label label1;
BackgroundWorker学习(转载)_事件处理_07        
private System.Windows.Forms.Button button4;
BackgroundWorker学习(转载)_多线程_14    }

BackgroundWorker学习(转载)_i++_174}

BackgroundWorker学习(转载)_i++_03
BackgroundWorker学习(转载)_i++_03

 

 

BackgroundWorker学习(转载)_sedBackgroundWorker学习(转载)_多线程_02Code
BackgroundWorker学习(转载)_i++_03using System;
BackgroundWorker学习(转载)_i++_03
using System.Collections.Generic;
BackgroundWorker学习(转载)_i++_03
using System.ComponentModel;
BackgroundWorker学习(转载)_i++_03
using System.Data;
BackgroundWorker学习(转载)_i++_03
using System.Drawing;
BackgroundWorker学习(转载)_i++_03
using System.Text;
BackgroundWorker学习(转载)_i++_03
using System.Windows.Forms;
BackgroundWorker学习(转载)_i++_03
using System.Threading;
BackgroundWorker学习(转载)_i++_03
using System.Net;
BackgroundWorker学习(转载)_i++_03
BackgroundWorker学习(转载)_i++_03
namespace WindowsApplication1
BackgroundWorker学习(转载)_i++_04BackgroundWorker学习(转载)_事件处理_05
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07    
public partial class Form1 : Form
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09    
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07        
//加载窗体
BackgroundWorker学习(转载)_事件处理_07
        public Form1()
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            InitializeComponent();
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_多线程_09BackgroundWorker学习(转载)_多线程_08        
define#region define
BackgroundWorker学习(转载)_事件处理_07        
int i = 0;
BackgroundWorker学习(转载)_事件处理_07        
int j = 0;
BackgroundWorker学习(转载)_事件处理_07        
bool f = false;
BackgroundWorker学习(转载)_多线程_14        
#endregion

BackgroundWorker学习(转载)_事件处理_07      
BackgroundWorker学习(转载)_事件处理_07        
private void button1_Click(object sender, EventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            backgroundWorker1.RunWorkerAsync();
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07        
//按钮单击事件启动后台线程DoWok事件
BackgroundWorker学习(转载)_事件处理_07
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            BackgroundWorker worker 
= (BackgroundWorker)sender;
BackgroundWorker学习(转载)_事件处理_07            
int num = int.Parse(textBox2.Text);
BackgroundWorker学习(转载)_事件处理_07            
if (f == false)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09            
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                
for (i = 0; i < num; i++)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09                
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                    
if (!worker.CancellationPending)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09                    
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                        j 
= i;
BackgroundWorker学习(转载)_事件处理_07                        Thread.Sleep(
100);
BackgroundWorker学习(转载)_事件处理_07                        worker.ReportProgress(i 
* 100 / num, i);
BackgroundWorker学习(转载)_事件处理_07                        
if (backgroundWorker1.CancellationPending)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09                        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07                            e.Cancel 
= true;
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07                            
break;
BackgroundWorker学习(转载)_多线程_14                        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14                    }

BackgroundWorker学习(转载)_多线程_14                }

BackgroundWorker学习(转载)_多线程_14            }

BackgroundWorker学习(转载)_事件处理_07            
else
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09            
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                
for (i = j; i < num; i++)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09                
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                    
if (!worker.CancellationPending)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09                    
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                        j 
= i;
BackgroundWorker学习(转载)_事件处理_07                        Thread.Sleep(
100);
BackgroundWorker学习(转载)_事件处理_07                        worker.ReportProgress(i 
* 100 / num, i);
BackgroundWorker学习(转载)_事件处理_07                        
if (backgroundWorker1.CancellationPending)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09                        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07                            e.Cancel 
= true;
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07                            
break;
BackgroundWorker学习(转载)_多线程_14                        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14                    }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14                }

BackgroundWorker学习(转载)_多线程_14            }

BackgroundWorker学习(转载)_事件处理_07            
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07        
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            progressBar1.Value 
= e.ProgressPercentage;
BackgroundWorker学习(转载)_事件处理_07            label3.Text 
= e.UserState.ToString();
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07        
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            
if (e.Cancelled)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09            
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                label3.Text 
= "已经取消!";
BackgroundWorker学习(转载)_多线程_14            }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07            
else
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09            
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07                MessageBox.Show(
"ok");
BackgroundWorker学习(转载)_多线程_14            }

BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07        
private void button2_Click(object sender, EventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            backgroundWorker1.CancelAsync();
BackgroundWorker学习(转载)_事件处理_07           
BackgroundWorker学习(转载)_事件处理_07            label3.Text 
= "正在取消。。";
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07        
private void button3_Click(object sender, EventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            f 
= true;
BackgroundWorker学习(转载)_事件处理_07            backgroundWorker1.RunWorkerAsync();
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07        
private void button4_Click(object sender, EventArgs e)
BackgroundWorker学习(转载)_多线程_08BackgroundWorker学习(转载)_多线程_09        
BackgroundWorker学习(转载)_用户界面_06{
BackgroundWorker学习(转载)_事件处理_07            backgroundWorker1.CancelAsync();
BackgroundWorker学习(转载)_事件处理_07         
BackgroundWorker学习(转载)_事件处理_07            
this.progressBar1.Value = 0;
BackgroundWorker学习(转载)_事件处理_07            f 
= false;
BackgroundWorker学习(转载)_事件处理_07            
this.label3.Text = "";
BackgroundWorker学习(转载)_事件处理_07            
this.textBox2.Text = "";
BackgroundWorker学习(转载)_事件处理_07            
BackgroundWorker学习(转载)_多线程_14        }

BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_事件处理_07
BackgroundWorker学习(转载)_多线程_14    }

BackgroundWorker学习(转载)_i++_174}