53.C#--多线程

namespace _19多线程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        //创建一个线程去执行这个方法
        Thread th = new Thread(Test);
        //将线程设置为后台线程
        th.IsBackground = true;
        //标记线程已准备就绪,随时可以开启
        th.Start();

    }
    public void Test()
    {
        for (int i = 0; i < 10000; i++)
        {
            textBox1.Text = i.ToString();
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //程序运行时取消跨线程的访问检查
        Control.CheckForIllegalCrossThreadCalls = false;
    }
}

}

猜你喜欢

转载自blog.51cto.com/12679593/2399031
今日推荐