线程实现 [英] Thread implementation

查看:39
本文介绍了线程实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows服务,该服务从Internet读取xml文件.我需要使用这样的线程,以便一次异步运行2个线程(共12个). 12个线程将按顺序运行,一次运行2个.请给我关于我将如何实施此建议..

谢谢.

I have a windows service which reads xml files from internet. I need to use threads such that 2 threads(of 12) run at a time, asynchronously. The 12 threads are to run in a sequential manner, 2 at a time. Please give me suggestion on how would i implement this..

Thanks.

推荐答案

如果一次只运行2个线程,那么拥有12个线程又有什么意义呢?为什么不只创建2个线程,让它们运行,而当一个完成时创建另一个线程呢?

无论如何, [
What''s the point of having 12 threads if only 2 are going to run at a time? Why not just create 2 threads, let them run and when one finishes create a another?

Anyway, this[^] should give you all the examples you need to start using threads.


写道:​​

我需要使用线程,使得2个线程(共12个)在一个时间,异步地. 12个线程将按顺序运行,一次运行2个.

I need to use threads such that 2 threads(of 12) run at a time, asynchronously. The 12 threads are to run in a sequential manner, 2 at a time.



那是一个可怕的主意,永远不要去做.我建议您使用ThreadPool,而不必理会一次管理多少个线程. ThreadPool将工作请求排入队列,并以最佳资源对其进行处理.



That is a terrible idea and never go for it. I''d suggest you to use a ThreadPool and forget about managing how many threads executes at a time. ThreadPool queues up the work requests and process them with optimum resources.


这篇关于线程实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆