111,126
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
ThreadPool.SetMinThreads(100, 100);
ThreadPool.SetMaxThreads(100, 100);
Console.WriteLine("start...");
DateTime now = DateTime.Now;
for (int i = 0; i < 50; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(CallBack), null);
}
Console.ReadLine();
}
static void CallBack(object o)
{
Thread.Sleep(5000);
int a, b;
ThreadPool.GetAvailableThreads(out a, out b);
string message = string.Format("CurrentThreadId is {0}\n " +
"CompletionPortThreads is :{1}", a.ToString(), b.ToString());
Console.WriteLine(message);
}
的直接在测试ashx中的ProcessRequest方法里也写下睡眠5秒的处理 public void ProcessRequest(HttpContext context)
{
System.Threading.Thread.Sleep(5000);
int a, b;
ThreadPool.GetAvailableThreads(out a, out b);
string message = string.Format("WorkerThreads is {0}\n " +
"CompletionPortThreads is :{1}", a.ToString(), b.ToString());
Debug.WriteLine(message);
}
第二次趋于稳定是15秒左右 以后都是.

