C#线程手册 [英] C# Manual Threading

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

问题描述

有没有人有这个节目在C#创建线程的数量不受限制任何好的资源,而无需使用线程池?

Does anyone have any good resources that show creating an unlimited number of threads in C# WITHOUT using a ThreadPool?

我知道有人可能有疑问的系统的体系结构线程数百或数千,所以让我解释的情况下CPU / OS将使这种努力毫无意义的任务。

I realize one might question the architecture of a system with hundreds or thousands of threads, so let me explain the task in case the CPU/OS will make this effort moot.

我有大约2500网址,我需要测试。其中一些是很慢的:在超过10秒的响应。在任何情况下,网络延迟弥补每个操作的约99.99%。

I have about 2500 URLs that I need to test. Some of them are very slow: in excess of 10 seconds to respond. In any event, network latency makes up about 99.99% of each operation.

我想尽可能快地测试所有2500的URL。

I'd like to test all 2500 urls as fast as possible.

我有线了一个测试,测试他们每个人在自己的线程。

I wired up a test that tests each of them in their own thread.

问题是我使用的线程池和我觉得默认的上限是25,所以这是没有好。我需要手动管理它们。我是出路在这里吃午餐?

The problem is I'm using the ThreadPool and I think the default limit is 25, so that's no good. I need to manage them manually. Am I way out to lunch here?

我实现了CPU / OS可能会同时限制每个CPU并发线程数目,但我相信这个限制是远远高于25。

I realize the CPU/OS will probably also limit the number of concurrent threads per CPU, but I trust this limit is WAY higher than 25.

关于建筑,我意识到我可能是整个箱子锁起来,如果我是要连接2000 HTTP线程,但是这是在运行的管理任务isoloation并提供可以采取尽可能多的资源。

Regarding architecture, I realize I may be locking up an entire box if I was to wire up 2 thousand HTTP threads, but this is an admin task that runs in isoloation and can take as many resources as are available.

感谢您的见解。

推荐答案

您不能创建的线程数量不受限制。如果你尝试,你会遇到很多问题。

You cannot create an unlimited number of threads. You will run into many problems if you try.

不过,可以增加C#中的线程池的默认线程数。只需使用 ThreadPool.SetMaxThreads 给线程凝聚更多的线程与合作。它可能会做的比任何手动线程尝试更好的工作(没有把精力大量进入手动过程)。

However, you can increase the default number of threads in the ThreadPool in C#. Just use ThreadPool.SetMaxThreads to give the thread pool more threads with which to work. It will likely do a better job than any manual threading attempts (without putting a LOT of effort into the manual process).

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

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