1 /// <summary>
2 /// 多线程1
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 private void button1_Click(object sender, EventArgs e)
7 {
8 //ThreadStart ts = new ThreadStart(dxc);
9 Thread th = new Thread(dxc);
10 th.IsBackground = true;
11 th.Start();
12 //dxc();
13 }
14
15 void dxc()
16 {
17 for (int i = 0; i < 20000; i++)
18 {
19 int a = int.Parse(tbnum.Text);
20 a++;
21 //MessageBox.Show(a.ToString());
22 this.tbnum.Text = a.ToString();
23 }
24 }
25
26 其中在运行的时候会报错,或窗体一闪而过,这个是话需要在此处加上如下代码即可解决
27 public Form多线程2()
28 {
29 InitializeComponent();
30 TextBox.CheckForIllegalCrossThreadCalls = false;//加上这句就可以了,
31 }