http://support.microsoft.com/kb/315582/zh-tw
(1) 呼叫同步方法
s = dlgt(3000, out iExecThread);
(2) 呼叫异步方法
BeginInvoke - 异步调用
EndInvoke - 获得结果, 如果异步方法还没执行完,就一直等着
IAsyncResult ar = dlgt.BeginInvoke(3000, out iExecThread, null, null);
(3) 呼叫异步方法 + 等待
WaitOne - 等待,
如果没有参数,就一直等着
如果有参数,则只等待相应时间 e.g : WaitOne(1000,false) - 等待1秒
IAsyncResult ar = dlgt.BeginInvoke(3000, out iExecThread, null, null);
ar.AsyncWaitHandle.WaitOne() ;
(4) 呼叫异步方法 + Callback 方法
AsyncCallback - 当异步方法结束后,调用'MyAsyncCallback'方法 - 可以用来获得返回值
AsyncCallback cb = new AsyncCallback(MyAsyncCallback);
// Initiate the Asynchronous call passing in the callback delegate
// and the delegate object used to initiate the call.
IAsyncResult ar = dlgt.BeginInvoke(3000, out iExecThread, cb , dlgt);