当前位置:编程学习 > C#/ASP.NET >>

一个线程的小问题

 private void button1_Click(object sender, EventArgs e)
        {
            string a=Thread.CurrentThread.Name;
            if (a != null)
            {
                Thread.CurrentThread.Abort();
                Thread.Sleep(1000);
            }
                Thread test1 = new Thread(new ThreadStart(threadtest));
                test1.Name = "thread1";
                test1.Start();
                           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string a = Thread.CurrentThread.Name;
            if (a != null)
            {
                Thread.CurrentThread.Abort();
                Thread.Sleep(1000);
            }
                Thread test2 = new Thread(new ThreadStart(threadtest));
                test2.Name = "thread2";
                test2.Start();
                          
        }
        private void threadtest() 
        {
            
            
            int j=1;
            while(true&&(label1.IsDisposed==false))
            {
                label1.Text = "";
                label1.Text =Convert.ToString(j);
                j++;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
        }


为什么当点击button2后就报错跳出:“集合在枚举数实例化后进行了修改”。麻烦帮我看看
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,