限制线程池的线程数 [英] Limiting the number of threadpool threads

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

问题描述

我使用 线程池 在我的应用程序。我已经首先通过使用以下设置线程池的限制:

I am using ThreadPool in my application. I have first set the limit of the thread pool by using the following:

ThreadPool.SetMaxThreads(m_iThreadPoolLimit,m_iThreadPoolLimit);
m_Events = new ManualResetEvent(false);

然后我去排队使用下面的工作

and then I have queued up the jobs using the following

WaitCallback objWcb = new WaitCallback(abc);
ThreadPool.QueueUserWorkItem(objWcb, m_objThreadData); 

下面ABC是,我调用函数的名称。 在此之后,我做了以下让我所有的线程来1点,主线程接管并继续进一步

Here abc is the name of the function that I am calling. After this I am doing the following so that all my threads come to 1 point and the main thread takes over and continues further

m_Events.WaitOne();

我的线程限制为3,我现在面临的问题是,对线程池限制设置为3 inspite,我的申请正在处理超过3个文件在同一时间,而它应该在处理只有3个文件一个时间。请帮我解决这个问题。

My thread limit is 3. The problem that I am facing is, inspite of the thread pool limit set to 3, my application is processing more than 3 files at the same time, whereas it was supposed to process only 3 files at a time. Please help me solve this issue.

推荐答案

您使用的是什么样的电脑?

What kind of computer are you using?

从<一个href="http://msdn.microsoft.com/en-us/library/system.threading.threadpool.setmaxthreads.aspx">MSDN

您不能设置工人的数量   螺纹或我数/ O   完成线程到一个更小的数   比在处理器的数量   计算机。

You cannot set the number of worker threads or the number of I/O completion threads to a number smaller than the number of processors in the computer.

如果你有4个核心,那么你就可以拥有最小的为4。

If you have 4 cores, then the smallest you can have is 4.

另外请注意:

如果公共语言运行库   托管,例如通过因特网   信息服务(IIS)或SQL   服务器,主机可以限制或prevent   更改线程池的大小。

If the common language runtime is hosted, for example by Internet Information Services (IIS) or SQL Server, the host can limit or prevent changes to the thread pool size.

如果这是由IIS托管的一个网站,那么你不能改变线程池的大小两种。

If this is a web site hosted by IIS then you cannot change the thread pool size either.

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

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