为什么Windows窗体中的这种基本多线程不起作用?

时间:2015-05-04 21:30:27

标签: c# asp.net .net multithreading winforms

我只想在win表单中实现线程的基本形式,但似乎无法做到。救命?基本上想要以不同的间隔填充文本框。

myfile.json

1 个答案:

答案 0 :(得分:0)

尝试在主应用中加入主题。

protected void Button1_Click(object sender, EventArgs e)

 {
                Thread work1 = new Thread(new 

ThreadStart(changestate1));
                        work1.Start();

                    Thread work2 = new Thread(new ThreadStart(changestate4));
                    work2.Start();


                    Thread work3 = new Thread(new ThreadStart(changestate7));
                    work3.Start();

                   **work1.Join();
                   work2.Join();
                   work3.Join();**



                }

                protected void changestate1()
                {
                    Thread.Sleep(999);
                    TextBox1.Text = "Work1";
                    changestate2();
                }
                protected void changestate2()
                {
                    Thread.Sleep(999);
                    TextBox2.Text = "Work1";
                    changestate3();
                }
                protected void changestate3()
                {
                    Thread.Sleep(999);
                    TextBox3.Text = "Work1";
                }
                protected void changestate4()
                {
                    Thread.Sleep(666);
                    TextBox4.Text = "Work2";
                    changestate5();
                }
                protected void changestate5()
                {
                    Thread.Sleep(666);
                    TextBox5.Text = "Work2";
                    changestate6();
                }
                protected void changestate6()
                {
                    Thread.Sleep(666);
                    TextBox6.Text = "Work2";
                }
                protected void changestate7()
                {
                    Thread.Sleep(333);
                    TextBox7.Text = "Work3";
                    changestate8();
                }
                protected void changestate8()
                {
                    Thread.Sleep(333);
                    TextBox8.Text = "Work3";
                    changestate9();
                }
                protected void changestate9()
                {
                    Thread.Sleep(333);
                    TextBox9.Text = "Work3";
                }