WaitHandle
===========
包装了为了共享某一资源而对排他访问进行等待的特定的操作系统对象.
该对象是典型地用作同步对象的基类. 从WaitHandle派生出来的类们定义了一个信号机制, 用于表示占有或释放对于一个共享资源的而访问, 但是它们使用继承而来的WaitHandle的方法来在需要等待访问共享资源的的时候阻塞自己.
WaitHandle.WaitOne方法, 作用是阻塞住当前线程, 直到当前的WaitHandle收到信号为止.
使用这个类的静态方法来阻塞一个线程直到一个或多个synchronization对象收到了信号. 具体的代码例子, 下面的原文出处中有.
摘自:
http://msdn.microsoft.com/en-us/library/system.threading.waithandle.aspx
ThreadPool.QueueUserWorkItem方法
================
将一个用于执行的方法添加到队列中. 这个方法会在线程池中有可用的线程时被执行.
http://msdn.microsoft.com/en-us/library/system.threading.threadpool.queueuserworkitem.aspx
WaitCallback代理
================
代表着被线程池中的线程执行的一个回调方法.
用法如下:
using System;
using System.Threading;
class Example {
void Main() {
// Queue the task.
new WaitCallback(ThreadProc));
7:
);
// If you comment out the Sleep, the main thread exits before
// the thread pool task runs. The thread pool uses background
// threads, which do not keep the application running. (This
// is a simple example of a race condition.)
13: Thread.Sleep(1000);
14:
);
16: }
17:
// This thread procedure performs the task.
void ThreadProc(Object stateInfo) {
// No state object was passed to QueueUserWorkItem, so
// stateInfo is null.
);
23: }
24: }