比如:
private Thread myThread;
void int() {
myThread= new Thread(new ThreadStart(Test));
myThread.Start();
}
void Test()
{
Sleep(500);
return;
}
请问在Test正常返回后,这个线程还在不在?处于什么状态?
------解决思路----------------------
Thread.Start()产生的线程在完成任务后,很快被系统所回收。而ThreadPool(线程池)方式下,线程在完成工作后会被保留一段时间以备resue。所以,当需求需要大量线程并发工作的时候,不建议使用ThreadPool方式,因为它会保持很多额外的线程。
As for the ThreadPool, it is designed to use as few threads as possible while also keeping the CPU busy. Ideally, the number of busy threads is equal to the number of CPU cores. However, if the pool detects that its threads are currently not using the CPU (sleeping, or waiting for another thread), it starts up more threads (at a rate of 1/second, up to some maximum) to keep the CPU busy.
------解决思路----------------------
这个线程还在不在?
在
处于什么状态?
StopRequested或者Stopped