???????????????APM??
???????????? ???????[ 2013/4/3 9:49:50 ] ????????
??????????????IAsyncResult??????????ref???ò???????????????????????????????????ú??????????????????????á?????
????1??????????ú???????????????????д?????????????????????У?????????????????????????????
????a??IAsyncResult??AsyncWaitHandle????????????????????????
????b?????IAsyncResult??IsCompleted???????????????????????????????????
????c?????????????? End*** ??????
????2??????????ú?????????????????????????У????????????????в????????????????н??С?
public class Calculate_Test
{
public static void Test()
{
CalculateLib cal = new CalculateLib();
// ????IAsyncResult?????????API
IAsyncResult calculateResult = cal.BeginCalculate(123?? 456?? AfterCallback?? cal);
// ????????ú???????????????????д?????????????????????У?????????????????????????????
// 1??IAsyncResult ?? AsyncWaitHandle ????????????????????????
// 2????? IAsyncResult ?? IsCompleted ???????????????????????????????????
// 3?????????????? End*** ??????
// ***********************************************************
// 1??calculateResult.AsyncWaitHandle.WaitOne();
// 2??while (calculateResult.IsCompleted) { Thread.Sleep(1000); }
// 3??
string resultStr = string.Empty;
int result = cal.EndCalculate(ref resultStr?? calculateResult);
}
/// <summary>
/// ?????????????????
/// </summary>
private static void AfterCallback(ref string resultStr?? IAsyncResult ar)
{
// ????????ú?????????????????????????У????????????????в????????????????н??С?
CalculateLib cal = ar.AsyncState as CalculateLib;
//int result = cal.EndInvoke(ref resultStr?? calculateResult1);
//if (result > 0) { }
}
}
?????????????н????????
??????????У????????????????????????÷???“invoke”????????÷???“BeginInvoke”??“EndInvoke”???????????÷???????????????п? (CLR) ???????????????????????????÷???????????????????????????????????????????С?
????????????????????????????????????????IAsyncResult???????????????????????BeginInvoke????IAsyncResult???????EndInvoke?????????
?????????
????????CalculateLib???е??????????????????????????£?
// ??ref??????????????
public delegate int AsyncInvokeDel(int num1?? int num2?? ref string resultStr);
public int Calculate(int num1?? int num2?? ref string resultStr)
{
resultStr = (num1 * num2).ToString();
return num1 * num2;
}
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
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