这是手动写的异步按纽,如果想动态写按纽,不知道怎么写。。
好象异步不能调用同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)
        {        } 
    }
}