This documentation is archived and is not being maintained.
LogicalMethodInfo.BeginInvoke Method
.NET Framework 1.1
Begins an asynchronous invocation of the method represented by this LogicalMethodInfo.
[Visual Basic] Public Function BeginInvoke( _ ByVal target As Object, _ ByVal values() As Object, _ ByVal callback As AsyncCallback, _ ByVal asyncState As Object _ ) As IAsyncResult [C#] public IAsyncResult BeginInvoke( object target, object[] values, AsyncCallback callback, object asyncState ); [C++] public: IAsyncResult* BeginInvoke( Object* target, Object* values __gc[], AsyncCallback* callback, Object* asyncState ); [JScript] public function BeginInvoke( target : Object, values : Object[], callback : AsyncCallback, asyncState : Object ) : IAsyncResult;
Parameters
- target
- The instance of the Object on which to invoke the method on.
- values
- An argument list for the invoked method. This is an array of objects with the same number, order, and type as the parameters of the method. If the method does not require any parameters, values should be a null reference (Nothing in Visual Basic).
- callback
- The delegate to call when the asynchronous invoke is complete. If callback is a null reference (Nothing in Visual Basic), the delegate is not called.
- asyncState
- State information that is passed on to the delegate.
Return Value
An IAsyncResult which is passed to EndInvoke to obtain the return values from the remote method call.
Exceptions
| Exception Type | Condition |
|---|---|
| TargetException | The target parameteris a null reference (Nothing in Visual Basic). |
| ArgumentException | The number, type, and order of parameters in values do not match the signature of the invoked method. |
| MemberAccessException | The caller does not have permission to invoke the method. |
Example
[Visual Basic] 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 [C#] 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."); } [C++] 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(S"BeginAdd"); MethodInfo* myEndMethod = myType->GetMethod(S"EndAdd"); // Create an instance of the LogicalMethodInfo class. MethodInfo* temp0 [] = {myBeginMethod,myEndMethod}; LogicalMethodInfo* myLogicalMethodInfo = (LogicalMethodInfo::Create(temp0, 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(0, MyEndIntimationMethod); // Begin to invoke the Add method. Object* temp1 [] = {__box(10),__box(10)}; IAsyncResult* myAsyncResult = myLogicalMethodInfo->BeginInvoke( myMathService,temp1,myAsyncCallback,0); // Wait until invoke is complete. myAsyncResult->AsyncWaitHandle->WaitOne(); // Get the result. Object* myReturnValue[]; myReturnValue = myLogicalMethodInfo->EndInvoke(myMathService,myAsyncResult); Console::WriteLine(S"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(S"Asynchronous call on Add method finished."); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
LogicalMethodInfo Class | LogicalMethodInfo Members | System.Web.Services.Protocols Namespace
Show: