????C#??????????????????C#????????????????????ν??е???????????????????????????C#???????
????.NET Framework ??????C#???????κη??????????????????????????????????????У????????????п?????????ж?????????????? BeginInvoke ?? EndInvoke ??????
????BeginInvoke ???????????C#?????á??????????????е????????????????????????????????????????????????????????BeginInvoke ??????????????C#????????ɡ?BeginInvoke ???? IasyncResult?????????????y????
????EndInvoke ???????????C#?????y???????? BeginInvoke ?????????? EndInvoke ?????????C#??????δ????EndInvoke ??????????C#????????ɡ?EndInvoke ??????????????????е?????? out ?? ref ???????? Visual Basic ??? ByRef ?? ByRef??????? BeginInvoke ????? IAsyncResult??
???????  Visual Studio .NET ?е??????????????? BeginInvoke ?? EndInvoke ?????????????????? Visual Studio ??????????????????????? C# ?? Visual Studio .NET????μ??????????????й????п????Щ????????????????????
???????????е???????????????? BeginInvoke ?? EndInvoke ????C#?????????÷??????????? BeginInvoke ???????
????· ?????Щ???????????? EndInvoke ??????????????ɡ?
????· ??? IAsyncResult.AsyncWaitHandle ??? WaitHandle????????? WaitOne ????????????????????? WaitHandle ?????????? EndInvoke??
????· ????? BeginInvoke ????? IAsyncResult?????C#?????ú???????????? EndInvoke??
????· ????????????????д???? BeginInvoke???÷?????C#???????????? ThreadPool ???????У?????????? EndInvoke??
???????棺?????C#????????????? EndInvoke??
??????????????????
???????????????????????????е??????? TestMethod???÷???????????????????????????????????????????????????TestMethod ????? out ???????? Visual Basic ??? ByRef?????????????ν???Щ???????? BeginInvoke ?? EndInvoke ??????С???????????????????? ref ???????? Visual Basic ??? ByRef????
?????????????????? TestMethod ??????? TestMethod ????У??????????????????????????????δ????С?
???????  ??????Щ?????TestMethod ??????? Main() ?????????????????TestMethod ????????? Main() ???????е? static ???????? Visual Basic ??? Shared????

 

using System;
using System.Threading;
public class AsyncDemo {
// The method to be executed asynchronously.
//
public string TestMethod(
int callDuration?? out int threadId) {
Console.WriteLine("Test method begins.");
Thread.Sleep(callDuration);
threadId = AppDomain.GetCurrentThreadId();
return "MyCallTime was " + callDuration.ToString();
}
}
// The delegate must have the same signature as the method
// you want to call asynchronously.
public delegate string AsyncDelegate(
int callDuration?? out int threadId);
using System;
using System.Threading;
public class AsyncDemo {
// The method to be executed asynchronously.
//
public string TestMethod(
int callDuration?? out int threadId) {
Console.WriteLine("Test method begins.");
Thread.Sleep(callDuration);
threadId = AppDomain.GetCurrentThreadId();
return "MyCallTime was " + callDuration.ToString();
}
}
// The delegate must have the same signature as the method
// you want to call asynchronously.
public delegate string AsyncDelegate(
int callDuration?? out int threadId);