ReceiveCompletedEventArgs 클래스

정의

ReceiveCompleted 이벤트에 대한 데이터를 제공합니다.Provides data for the ReceiveCompleted event. 비동기 수신 작업에서 이벤트 처리기가 호출되면 이 클래스의 인스턴스가 해당 처리기로 전달됩니다.When your asynchronous receive operation calls an event handler, an instance of this class is passed to the handler.

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

예제

다음 코드 예제에 대 한 이벤트 처리기를 만듭니다는 ReceiveCompleted 이벤트 및 이벤트를 사용 하 여 대리자를 사용 하 여 연결 된 ReceiveCompletedEventHandler합니다.The following code example creates an event handler for the ReceiveCompleted event and associates it with the event delegate by using the ReceiveCompletedEventHandler. 이벤트 처리기 MyReceiveCompleted, 큐에서 메시지를 수신 및 화면으로 해당 본문을 작성 합니다.The event handler, MyReceiveCompleted, receives a message from a queue and writes its body to the screen.

#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

설명

이벤트 알림을 사용 하 여 큐에서 메시지를 비동기적으로 받을 때 메시지를 처리 하는 메서드를 만들어야 합니다.When you use event notification to receive messages asynchronously from the queue, you must create a method that handles your message processing. 코드를 호출 해야 BeginReceive 여 비동기 처리를 시작 합니다.Your code must call BeginReceive to begin the asynchronous processing. 애플리케이션을 통해 알려집니다 메시지가 수신 되 면는 ReceiveCompleted 이벤트입니다.When a message is received, your application is notified through the ReceiveCompleted event. 인스턴스의 ReceiveCompletedEventArgs 이벤트 처리기를 호출 하는 이벤트 대리자에 전달 됩니다.An instance of ReceiveCompletedEventArgs is passed into the event delegate that calls your event handler. 연결 된 데이터를 ReceiveCompleted 이벤트는 대리자의에 포함 된 AsyncResult 매개 변수입니다.The data associated with the ReceiveCompleted event is contained in the delegate's AsyncResult parameter.

이벤트 완료에 대 한 알림을 제공 하는 방법은 두 가지: 이벤트 알림 및 콜백 합니다.There are two ways to provide notification of event completion: event notification and callbacks. ReceiveCompletedEventArgs 이벤트 알림 에서만 사용 됩니다.ReceiveCompletedEventArgs is used only with event notification. 콜백 및 이벤트 알림을 비교 내용은 "이벤트 및을 참조 하세요. 콜백 "MSDN에 있습니다.For information comparing callbacks and event notification, see "Events vs. Callbacks" on MSDN.

ReceiveCompletedEventArgs 액세스를 제공 비동기의 끝을 초기화 하는 메시지에 작업을 통해 수신 된 Message 멤버입니다.ReceiveCompletedEventArgs provides access to the message that initiated the end of the asynchronous receive operation, through the Message member. 메시지에 대 한 대체 액세스 이며 동작에 대 한 호출 하는 것과 매우 MessageQueue.EndReceive합니다.This is an alternate access to the message, and behaves much the same as a call to MessageQueue.EndReceive.

속성

AsyncResult

요청한 비동기 작업의 결과를 가져오거나 설정합니다.Gets or sets the result of the asynchronous operation requested.

Message

비동기 수신 작업과 관련된 메시지를 가져옵니다.Gets the message associated with the asynchronous receive operation.

메서드

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

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

기본 해시 함수로 작동합니다.Serves as the default hash function.

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

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

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

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

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

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(다음에서 상속됨 Object)

적용 대상

추가 정보