LogicalMethodInfo.BeginInvoke(Object, Object[], AsyncCallback, Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
開始這個 LogicalMethodInfo 所表示之方法的非同步引動過程。
public:
IAsyncResult ^ BeginInvoke(System::Object ^ target, cli::array <System::Object ^> ^ values, AsyncCallback ^ callback, System::Object ^ asyncState);
public IAsyncResult BeginInvoke (object target, object[] values, AsyncCallback callback, object asyncState);
member this.BeginInvoke : obj * obj[] * AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke (target As Object, values As Object(), callback As AsyncCallback, asyncState As Object) As IAsyncResult
參數
- values
- Object[]
叫用方法或的引數清單。 這是與方法的參數具有相同數目、順序和型別的物件陣列。 如果方法不需要任何參數,values
應該為 null
。
- callback
- AsyncCallback
非同步叫用完成後,要呼叫的委派。 如果 callback
為 null
,則不呼叫委派。
- asyncState
- Object
傳入委派的狀態資訊。
傳回
IAsyncResult,傳遞至 EndInvoke(Object, IAsyncResult) 以自遠端方法呼叫取得傳回值。
例外狀況
target
參數為 null
。
values
中參數的數目、型別和順序與叫用方法的簽章不符。
呼叫端沒有叫用方法的使用權限。
範例
public:
[PermissionSet(SecurityAction::Demand, Name="FullTrust")]
static void main()
{
// Get the type information.
// Note: The MyMath class is a proxy class generated by the Wsdl.exe
// utility for the Math Web service. This class can also be found in
// the SoapHttpClientProtocol class example.
Type^ myType = MyMath::MyMath::typeid;
// Get the method info.
MethodInfo^ myBeginMethod = myType->GetMethod( "BeginAdd" );
MethodInfo^ myEndMethod = myType->GetMethod( "EndAdd" );
// Create an instance of the LogicalMethodInfo class.
array<MethodInfo^>^ temp0 = { myBeginMethod, myEndMethod };
LogicalMethodInfo^ myLogicalMethodInfo =
( LogicalMethodInfo::Create( temp0, LogicalMethodTypes::Async ) )[ 0 ];
// Get an instance of the proxy class.
MyMath::MyMath^ myMathService = gcnew MyMath::MyMath;
// Call the MyEndIntimationMethod method to intimate the end of
// the asynchronous call.
AsyncCallback^ myAsyncCallback = gcnew AsyncCallback( MyEndIntimationMethod );
// Begin to invoke the Add method.
array<Object^>^ temp1 = { 10, 10 };
IAsyncResult^ myAsyncResult = myLogicalMethodInfo->BeginInvoke(
myMathService, temp1, myAsyncCallback, nullptr );
// Wait until invoke is complete.
myAsyncResult->AsyncWaitHandle->WaitOne();
// Get the result.
array<Object^>^ myReturnValue;
myReturnValue = myLogicalMethodInfo->EndInvoke( myMathService, myAsyncResult );
Console::WriteLine( "Sum of 10 and 10 is {0}", myReturnValue[ 0 ] );
}
// This method will be called at the end of the asynchronous call.
static void MyEndIntimationMethod( IAsyncResult^ /*Result*/ )
{
Console::WriteLine( "Asynchronous call on Add method finished." );
}
public static void Main()
{
// Get the type information.
// Note: The MyMath class is a proxy class generated by the Wsdl.exe
// utility for the Math Web service. This class can also be found in
// the SoapHttpClientProtocol class example.
Type myType = typeof(MyMath.MyMath);
// Get the method info.
MethodInfo myBeginMethod = myType.GetMethod("BeginAdd");
MethodInfo myEndMethod = myType.GetMethod("EndAdd");
// Create an instance of the LogicalMethodInfo class.
LogicalMethodInfo myLogicalMethodInfo =
(LogicalMethodInfo.Create(new MethodInfo[] {myBeginMethod,myEndMethod},
LogicalMethodTypes.Async))[0];
// Get an instance of the proxy class.
MyMath.MyMath myMathService = new MyMath.MyMath();
// Call the MyEndIntimationMethod method to intimate the end of
// the asynchronous call.
AsyncCallback myAsyncCallback = new AsyncCallback(MyEndIntimationMethod);
// Begin to invoke the Add method.
IAsyncResult myAsyncResult = myLogicalMethodInfo.BeginInvoke(
myMathService,new object[]{10,10},myAsyncCallback,null);
// Wait until invoke is complete.
myAsyncResult.AsyncWaitHandle.WaitOne();
// Get the result.
object[] myReturnValue;
myReturnValue = myLogicalMethodInfo.EndInvoke(myMathService,myAsyncResult);
Console.WriteLine("Sum of 10 and 10 is " + myReturnValue[0]);
}
// This method will be called at the end of the asynchronous call.
static void MyEndIntimationMethod(IAsyncResult Result)
{
Console.WriteLine("Asynchronous call on Add method finished.");
}
Public Shared Sub Main()
' Get the type information.
' Note: The MyMath class is a proxy class generated by the Wsdl.exe
' utility for the Math Web Service. This class can also be found in
' the SoapHttpClientProtocol class example.
Dim myType As Type = GetType(MyMath.MyMath)
' Get the method info.
Dim myBeginMethod As MethodInfo = myType.GetMethod("BeginAdd")
Dim myEndMethod As MethodInfo = myType.GetMethod("EndAdd")
' Create an instance of the LogicalMethodInfo class.
Dim myLogicalMethodInfo As LogicalMethodInfo = _
LogicalMethodInfo.Create(New MethodInfo() {myBeginMethod, myEndMethod}, _
LogicalMethodTypes.Async)(0)
' Get an instance of the proxy class.
Dim myMathService As New MyMath.MyMath()
' Call the MyEndIntimationMethod method to intimate the end of
' the asynchronous call.
Dim myAsyncCallback As New AsyncCallback(AddressOf MyEndIntimationMethod)
' Beging to invoke the Add method.
Dim myAsyncResult As IAsyncResult = _
myLogicalMethodInfo.BeginInvoke( _
myMathService, New Object() {10, 10}, myAsyncCallback, Nothing)
' Wait until invoke is complete.
myAsyncResult.AsyncWaitHandle.WaitOne()
' Get the result.
Dim myReturnValue() As Object
myReturnValue = myLogicalMethodInfo.EndInvoke(myMathService, myAsyncResult)
Console.WriteLine(("Sum of 10 and 10 is " & myReturnValue(0)))
End Sub
' This method will be called at the end of asynchronous call.
Shared Sub MyEndIntimationMethod(ByVal Result As IAsyncResult)
Console.WriteLine("Asynchronous call on method 'Add' finished.")
End Sub