如果你的应用程序拥有大量的线程并花费大量的时间阻塞在一个Wait Handle上,那么你要考虑使用线程池(Thead pooling)来处理。线程池通过合并多个Wait Handle来节约等待的时间。当Wait Handle被激活时,使用线程池你需要注册一个Wait Handle到一个委托去执行。通过调用ThreadPool.RegisterWaitForSingleObject方法:
class
Test
{
static ManualResetEvent starter = new ManualResetEvent( false );
public static void Main()
{
ThreadPool.RegisterWaitForSingleObject(starter, Go, " hello " , - 1 , true );
Thread.Sleep(
{
static ManualResetEvent starter = new ManualResetEvent( false );
public static void Main()
{
ThreadPool.RegisterWaitForSingleObject(starter, Go, " hello " , - 1 , true );
Thread.Sleep(