本文介绍了.NET线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 此代码有什么问题。所有我想测试的是3个进度条和 一个按钮。在buttonclick上我创建3个线程,每个线程调用一个方法 ,然后更新进度条并且它可以工作。我想知道是否可以使用这个 。 谢谢 private void button1_Click(object sender,System.EventArgs e) { ThreadStart job = new ThreadStart(onemethod); Thread thread = new Thread(job ); thread.Start(); ThreadStart job1 =新的ThreadStart(secondmethod); 线程thread1 =新线程(job1); thread1.Start(); ThreadStart job2 =新的ThreadStart(thirdmethod) ; 线程thread2 =新线程(job2); thread2.Start(); } public void onemethod() { for(int i = 0; i< 100; i ++) { progressBar1.Value = i; Thread.Sleep(100); } } public void secondmethod( ) { for(int i = 0; i< 100; i ++) { progressBar2.Value = i; Thread.Sleep(100); } } public void thirdmethod() { for(int i = 0; i< 100; i ++) { progressBar3.Value = i; Thread.Sleep(100); } }What is wrong with this code. All i am trying to test is 3 progressbar andone button. On buttonclick i create 3 threads and each thread calls a methodwhich in turn updates the progressbar and it works. I would to know if thiscan be used.Thanksprivate void button1_Click(object sender, System.EventArgs e){ThreadStart job = new ThreadStart(onemethod);Thread thread = new Thread(job);thread.Start();ThreadStart job1 = new ThreadStart(secondmethod);Thread thread1 = new Thread(job1);thread1.Start();ThreadStart job2 = new ThreadStart(thirdmethod);Thread thread2 = new Thread(job2);thread2.Start();}public void onemethod(){for (int i=0;i<100;i++){progressBar1.Value = i;Thread.Sleep(100);}}public void secondmethod(){for (int i=0;i<100;i++){progressBar2.Value = i;Thread.Sleep(100);}}public void thirdmethod(){for (int i=0;i<100;i++){progressBar3.Value = i;Thread.Sleep(100);}}推荐答案 这篇关于.NET线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 06:31