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과 거의 동일하게 동작합니다.

속성

Name Description
AsyncResult

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

Message

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

메서드

Name Description
Equals(Object)

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

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

기본 해시 함수로 사용됩니다.

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보