C#???????????
???????????? ???????[ 2014/2/8 10:51:49 ] ???????????? ???????
????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);
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11