ReceiveCompletedEventArgs 클래스

정의

ReceiveCompleted 이벤트에 대한 데이터를 제공합니다. 비동기 수신 작업에서 이벤트 처리기가 호출되면 이 클래스의 인스턴스가 해당 처리기로 전달됩니다.

public ref class ReceiveCompletedEventArgs : EventArgs
public class ReceiveCompletedEventArgs : EventArgs
type ReceiveCompletedEventArgs = class
    inherit EventArgs
Public Class ReceiveCompletedEventArgs
Inherits EventArgs
상속
ReceiveCompletedEventArgs

예제

다음 코드 예제에 대 한 이벤트 처리기를 만듭니다는 ReceiveCompleted 이벤트 및 이벤트를 사용 하 여 대리자를 사용 하 여 연결 된 ReceiveCompletedEventHandler합니다. 이벤트 처리기 MyReceiveCompleted, 큐에서 메시지를 수신 및 화면으로 해당 본문을 작성 합니다.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   //*************************************************
   // Provides an event handler for the ReceiveCompleted
   // event.
   //*************************************************
   static void MyReceiveCompleted( Object^ source, ReceiveCompletedEventArgs^ asyncResult )
   {
      // Connect to the queue.
      MessageQueue^ mq = dynamic_cast<MessageQueue^>(source);

      // End the asynchronous Receive operation.
      Message^ m = mq->EndReceive( asyncResult->AsyncResult );

      // Display message information on the screen.
      Console::WriteLine( "Message: {0}", m->Body );

      // Restart the asynchronous Receive operation.
      mq->BeginReceive();
      return;
   }
};


//*************************************************
// Provides an entry point into the application.
//         
// This example performs asynchronous receive operation
// processing.
//*************************************************
int main()
{
   // Create an instance of MessageQueue. Set its formatter.
   MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
   array<Type^>^p = gcnew array<Type^>(1);
   p[ 0 ] = String::typeid;
   myQueue->Formatter = gcnew XmlMessageFormatter( p );

   // Add an event handler for the ReceiveCompleted event.
   myQueue->ReceiveCompleted += gcnew ReceiveCompletedEventHandler( MyNewQueue::MyReceiveCompleted );

   // Begin the asynchronous receive operation.
   myQueue->BeginReceive();

   // Do other work on the current thread.
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{
    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example performs asynchronous receive operation
        // processing.
        //**************************************************

        public static void Main()
        {
            // Create an instance of MessageQueue. Set its formatter.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(String)});

            // Add an event handler for the ReceiveCompleted event.
            myQueue.ReceiveCompleted += new
                ReceiveCompletedEventHandler(MyReceiveCompleted);
            
            // Begin the asynchronous receive operation.
            myQueue.BeginReceive();
            
            // Do other work on the current thread.

            return;
        }

        //**************************************************
        // Provides an event handler for the ReceiveCompleted
        // event.
        //**************************************************
        
        private static void MyReceiveCompleted(Object source,
            ReceiveCompletedEventArgs asyncResult)
        {
            // Connect to the queue.
            MessageQueue mq = (MessageQueue)source;

            // End the asynchronous Receive operation.
            Message m = mq.EndReceive(asyncResult.AsyncResult);

            // Display message information on the screen.
            Console.WriteLine("Message: " + (string)m.Body);

            // Restart the asynchronous Receive operation.
            mq.BeginReceive();
            
            return;
        }
    }
}
Imports System.Messaging

Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        '		 
        ' This example performs asynchronous receive operation
        ' processing.
        '

        Public Shared Sub Main()

            ' Create an instance of MessageQueue. Set its formatter.
            Dim myQueue As New MessageQueue(".\myQueue")
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType([String])})

            ' Add an event handler for the ReceiveCompleted event.
            AddHandler myQueue.ReceiveCompleted, AddressOf _
                MyReceiveCompleted

            ' Begin the asynchronous receive operation.
            myQueue.BeginReceive()

            ' Do other work on the current thread.

            Return

        End Sub


        '
        ' Provides an event handler for the ReceiveCompleted
        ' event.
        '

        Private Shared Sub MyReceiveCompleted(ByVal [source] As _
            [Object], ByVal asyncResult As ReceiveCompletedEventArgs)

            ' Connect to the queue.
            Dim mq As MessageQueue = CType([source], MessageQueue)

            ' End the asynchronous Receive operation.
            Dim m As Message = mq.EndReceive(asyncResult.AsyncResult)

            ' Display message information on the screen.
            Console.WriteLine(("Message: " + CStr(m.Body)))

            ' Restart the asynchronous Receive operation.
            mq.BeginReceive()

            Return

        End Sub

End Class

설명

이벤트 알림을 사용 하 여 큐에서 메시지를 비동기적으로 받을 때 메시지를 처리 하는 메서드를 만들어야 합니다. 코드를 호출 해야 BeginReceive 여 비동기 처리를 시작 합니다. 애플리케이션을 통해 알려집니다 메시지가 수신 되 면는 ReceiveCompleted 이벤트입니다. 인스턴스의 ReceiveCompletedEventArgs 이벤트 처리기를 호출 하는 이벤트 대리자에 전달 됩니다. 연결 된 데이터를 ReceiveCompleted 이벤트는 대리자의에 포함 된 AsyncResult 매개 변수입니다.

이벤트 완료에 대 한 알림을 제공 하는 방법은 두 가지: 이벤트 알림 및 콜백 합니다. ReceiveCompletedEventArgs 이벤트 알림 에서만 사용 됩니다. 콜백 및 이벤트 알림을 비교 내용은 "이벤트 및을 참조 하세요. 콜백 "MSDN에 있습니다.

ReceiveCompletedEventArgs 액세스를 제공 비동기의 끝을 초기화 하는 메시지에 작업을 통해 수신 된 Message 멤버입니다. 메시지에 대 한 대체 액세스 이며 동작에 대 한 호출 하는 것과 매우 MessageQueue.EndReceive합니다.

속성

AsyncResult

요청한 비동기 작업의 결과를 가져오거나 설정합니다.

Message

비동기 수신 작업과 관련된 메시지를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보