【发布时间】:2011-12-14 09:18:17
【问题描述】:
我在多线程中遇到问题。
案例:我正在创建 exe 以从另一个网站下载照片,由于有 1000 张来自其他服务器的照片,我已经实现了多线程,但这不能正常工作
在 Main() 中,我调用了一个名为 ThreadMain(); 的方法
在ThreadMain(); 函数中,我们将任务分为十个线程,如
ThreadStart jobOne = new ThreadStart(ThreadOne);
Thread threadOne = new Thread(jobOne);
// Start the thread
threadOne.Start();
ThreadStart jobTwo = new ThreadStart(ThreadTwo);
Thread threadTwo = new Thread(jobTwo);
threadTwo.Start();
ThreadStart jobThree = new ThreadStart(ThreadThree);
Thread threadThree = new Thread(jobThree);
threadThree.Start();
等多达 10 个线程
然后我们进一步定义了像
静态 void ThreadOne() { 数据库任务 }
静态 void ThreadTwo() { 数据库任务 }
静态 void ThreadThree() { 数据库任务 }
最多 10 个职位 但是在完成线程后,控制台窗口不会自行关闭或者我无法知道线程是否已完成?请指教
【问题讨论】:
-
你是在使用join来等待线程完成吗?
标签: multithreading c#-4.0