????C#??????????????? EndInvoke ?????????
????????з????????????? BeginInvoke ????????????????Щ???????????? EndInvoke??EndInvoke ???C#???????????????????????????????????????????????????????? EndInvoke?????????????????????????????????

 

public class AsyncMain {
static void Main(string[] args) {
// The asynchronous method puts the thread id here.
int threadId;
// Create an instance of the test class.
AsyncDemo ad = new AsyncDemo();
// Create the delegate.
AsyncDelegate dlgt = new AsyncDelegate(ad.TestMethod);
// Initiate the asychronous call.
IAsyncResult ar = dlgt.BeginInvoke(3000??
out threadId?? null?? null);
Thread.Sleep(0);
Console.WriteLine("Main thread {0} does some work."??
AppDomain.GetCurrentThreadId());
// Call EndInvoke to Wait for
//the asynchronous call to complete??
// and to retrieve the results.
string ret = dlgt.EndInvoke(out threadId?? ar);
Console.WriteLine("The call executed on thread {0}??
with return value "{1}"."?? threadId?? ret);
}
}

 

????C#??????????????? WaitHandle ?????????
??????? WaitHandle ??????????????????????????????? BeginInvoke ????? IAsyncResult ?? AsyncWaitHandle ????????? WaitHandle??C#?????????????? WaitHandle ??????????????????????? WaitOne ???????
???????????? WaitHandle??????C#??????????????????????? EndInvoke ???????????????????????????

public class AsyncMain {
static void Main(string[] args) {
// The asynchronous method puts the thread id here.
int threadId;
// Create an instance of the test class.
AsyncDemo ad = new AsyncDemo();
// Create the delegate.
AsyncDelegate dlgt = new AsyncDelegate(ad.TestMethod);
// Initiate the asychronous call.
IAsyncResult ar = dlgt.BeginInvoke(3000??
out threadId?? null?? null);
Thread.Sleep(0);
Console.WriteLine("Main thread {0} does some work."??
AppDomain.GetCurrentThreadId());
// Wait for the WaitHandle to become signaled.
ar.AsyncWaitHandle.WaitOne();
// Perform additional processing here.
// Call EndInvoke to retrieve the results.
string ret = dlgt.EndInvoke(out threadId?? ar);
Console.WriteLine("The call executed on thread {0}??
with return value "{1}"."?? threadId?? ret);
}
}