日期:2014-05-17 浏览次数:20461 次
List<BackgroundWorker> bw = new List<BackgroundWorker>();
int t = 10;
int c = 1;
public Form2()
{
InitializeComponent();
for (int i = 0; i < t; i++)
{
bw.Add(new BackgroundWorker());
bw[i].WorkerSupportsCancellation = true;
bw[i].DoWork += new DoWorkEventHandler(bw_DoWork);
bw[i].RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
}
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (c++ == t)
{
if (e.Cancelled)
{
this.richTextBox1.Text += "操作暂停!"; ;
}
else
{
this.richTextBox1.Text += "操作完成!";
}
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
int j = Convert.ToInt32(e.Argument);
for (int i = j; i < 100; i = i + t)
{