??????????????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; 
}