다음을 통해 공유


LogicalMethodInfo.BeginInvoke(Object, Object[], AsyncCallback, Object) 메서드

정의

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

매개 변수

target
Object

메서드를 호출할 Object의 인스턴스입니다.

values
Object[]

호출된 메서드에 대한 인수 목록입니다. 이것은 해당 메서드의 매개 변수와 같은 개수, 순서 및 형식을 가진 개체의 배열입니다. 메서드에 매개 변수가 필요하지 않는 경우 valuesnull이어야 합니다.

callback
AsyncCallback

비동기 호출이 완료될 때 호출할 대리자입니다. callbacknull이면 대리자가 호출되지 않습니다.

asyncState
Object

해당 대리자로 전달되는 상태 정보입니다.

반환

IAsyncResult

원격 메서드 호출에서 반환 값을 가져오기 위해 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

적용 대상