这是手动写的异步按纽,如果想动态写按纽,不知道怎么写。。
好象异步不能调用同1个方法的?只运行一个异步操作。[
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Do1(backgroundWorker1, e);
} private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else
{
textBox1.Text = "OVER";
}
} private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "aaa";
backgroundWorker1.RunWorkerAsync();
} private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "aaa";
backgroundWorker2.RunWorkerAsync();
} private void button3_Click(object sender, EventArgs e)
{
textBox3.Text = "aaa";
backgroundWorker3.RunWorkerAsync();
} private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
Do2(backgroundWorker2, e);
} private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else
{
textBox2.Text = "OVER";
}
} private void backgroundWorker3_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else
{
textBox3.Text = "OVER";
}
}
public void Do1(BackgroundWorker w, DoWorkEventArgs e)
{ for (int j = 0; j < 100000; j++)
{
for (int o = 0; o < 1000; o++)
{
int k = 0;
if (j % 10 == 0)
{
k += j; }
} }
}
public void Do2(BackgroundWorker w, DoWorkEventArgs e)
{ for (int j = 0; j < 100000; j++)
{
for (int o = 0; o < 1000; o++)
{
int k = 0;
if (j % 10 == 0)
{
k += j; }
} }
}
public void Do3(BackgroundWorker w, DoWorkEventArgs e)
{ for (int j = 0; j < 100000; j++)
{
for (int o = 0; o < 1000; o++)
{
int k = 0;
if (j % 10 == 0)
{
k += j; }
} }
} private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{ }
}
}
好象异步不能调用同1个方法的?只运行一个异步操作。[
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Do1(backgroundWorker1, e);
} private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else
{
textBox1.Text = "OVER";
}
} private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "aaa";
backgroundWorker1.RunWorkerAsync();
} private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "aaa";
backgroundWorker2.RunWorkerAsync();
} private void button3_Click(object sender, EventArgs e)
{
textBox3.Text = "aaa";
backgroundWorker3.RunWorkerAsync();
} private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
Do2(backgroundWorker2, e);
} private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else
{
textBox2.Text = "OVER";
}
} private void backgroundWorker3_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else
{
textBox3.Text = "OVER";
}
}
public void Do1(BackgroundWorker w, DoWorkEventArgs e)
{ for (int j = 0; j < 100000; j++)
{
for (int o = 0; o < 1000; o++)
{
int k = 0;
if (j % 10 == 0)
{
k += j; }
} }
}
public void Do2(BackgroundWorker w, DoWorkEventArgs e)
{ for (int j = 0; j < 100000; j++)
{
for (int o = 0; o < 1000; o++)
{
int k = 0;
if (j % 10 == 0)
{
k += j; }
} }
}
public void Do3(BackgroundWorker w, DoWorkEventArgs e)
{ for (int j = 0; j < 100000; j++)
{
for (int o = 0; o < 1000; o++)
{
int k = 0;
if (j % 10 == 0)
{
k += j; }
} }
} private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{ }
}
}
解决方案 »
- PictureBox Vs2010
- Panel滚动,控件重画问题。
- image类型如何比较
- COM+分布式事务处理无法访问远程数据库服务器
- C#中如何使用Socket传送视频文件啊??
- c#如何用最少的资源打开一个超大的文本文件,并且在指定位置插入一段文本。
- 如何方便的修改用C#编写的WebApplication中的100个Label控件的TOOLTIP属性的值?
- c#调用ocx控件,返回值为空,100分求高手帮忙,急!!!
- 打开水晶报表时显示“未将对象引用设置到对象的实例”,只有10分,全部送出
- WinForm下面的DataGridView数据绑定?
- C#中listview的用法
- 请教一个问题
一个按扭一个CLICK.....