異步調用
Linkage為http://www.codeproject.com/csharp/AsyncMethodInvocation.asp
<PRE lang=cs id=pre19 style="MARGIN-TOP: 0px">private void CallFooWithOutAndRefParametersWithCallback()
{
// create the paramets to pass to the function
string strParam1 = "Param1";
int intValue = 100;
ArrayList list = new ArrayList();
list.Add("Item1");
// create the delegate
DelegateWithOutAndRefParameters delFoo =
new DelegateWithOutAndRefParameters(FooWithOutAndRefParameters);
delFoo.BeginInvoke(strParam1,
out intValue,
ref list,
new AsyncCallback(CallBack), // callback delegate!
null);
}
private void CallBack(IAsyncResult ar)
{
// define the output parameter
int intOutputValue;
ArrayList list = null;
// first case IAsyncResult to an AsyncResult object, so we can get the
// delegate that was used to call the function.
AsyncResult result = (AsyncResult)ar;
// grab the delegate
DelegateWithOutAndRefParameters del =
(DelegateWithOutAndRefParameters) result.AsyncDelegate;
// now that we have the delegate,
// we must call EndInvoke on it, so we can get all
// the information about our method call.
string strReturnValue = del.EndInvoke(out intOutputValue,
ref list, ar);
}</PRE>