.net maxWorkerThreads和线程数问题
我创建了一个ASP.NET应用程序,它在无限循环中创建线程。我在.net maxWorkerThreads和线程数问题,.net,asp.net,multithreading,iis-7,iis-6,.net,Asp.net,Multithreading,Iis 7,Iis 6,我创建了一个ASP.NET应用程序,它在无限循环中创建线程。我在machine.config中的processModel中将maxWorkerThreads设置为20 当我在perfmon中检查线程数时,在辅助进程中创建了大约7000个线程 在PageLoad()中,我有: using System.Threading; ... int count = 0; var threadList = new System.Collections.Generic.List<System.Thread
machine.config
中的processModel
中将maxWorkerThreads
设置为20
当我在perfmon中检查线程数时,在辅助进程中创建了大约7000个线程
在PageLoad()
中,我有:
using System.Threading;
...
int count = 0;
var threadList = new System.Collections.Generic.List<System.Threading.Thread>();
try
{
while (true)
{
Thread newThread = new Thread(ThreadStart(DummyCall), 1024);
newThread.Start();
threadList.Add(newThread);
count++;
}
}
catch (Exception ex)
{
Response.Write(count + " : " + ex.ToString());
}
如何使用IIS6/7限制ASP.NET中的线程创建?如何创建线程?如果您使用的是
ThreadPool.QueueUserWorkItem
,那么我预计在任何给定时间运行的线程不会超过20个
但是,如果您正在生成线程并只调用
.Start()
,则可以创建任意数量的线程。您创建的线程不是ASP.NET工作线程,并且不受processModel
指定的限制
在这里,您只是在创建普通的.NET线程,除了进程可用的最大内存量来限制您可以创建的线程数量之外,几乎没有其他内容
我会考虑使用这个类。
但是,您应该质疑为什么需要在ASP.NET页面中生成后台工作线程。这通常被认为是个坏主意。那么我们有什么办法可以限制它吗??
void DummyCall()
{
System.Threading.Thread.Sleep(1000000000);
}