当我编写下面的代码时,为什么我会得到可用的线程号码,如1022,1020。 因为我使用线程池,所以我必须获得最多25个线程。线程池中的活动线程号
我猜输出线程数是系统上的可用线程。我需要在我的线程池中获取可用的线程号,在win表单应用程序中。
private void Foo()
{
int intAvailableThreads, intAvailableIoAsynThreds;
// ask the number of avaialbe threads on the pool,
//we really only care about the first parameter.
ThreadPool.GetAvailableThreads(out intAvailableThreads,
out intAvailableIoAsynThreds);
// build a message to log
string strMessage =
String.Format(@"Is Thread Pool: {1},
Thread Id: {2} Free Threads {3}",
Thread.CurrentThread.IsThreadPoolThread.ToString(),
Thread.CurrentThread.GetHashCode(),
intAvailableThreads);
// check if the thread is on the thread pool.
Trace.WriteLine(strMessage);
// create a delay...
Thread.Sleep(30000);
return;
}
非常感谢..
(注:我的代码http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx) 好文章!
毫无疑问,文章是优秀的,但它是在2006年写的! – Azmeer 2017-01-10 02:03:47