ReceiveCompletedEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia ReceiveCompleted. Gdy asynchroniczna operacja odbierania wywołuje procedurę obsługi zdarzeń, wystąpienie tej klasy jest przekazywane do programu obsługi.

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

Przykłady

Poniższy przykład kodu tworzy procedurę obsługi zdarzeń dla ReceiveCompleted zdarzenia i kojarzy je z delegatem zdarzenia przy użyciu elementu ReceiveCompletedEventHandler. Procedura obsługi MyReceiveCompletedzdarzeń odbiera komunikat z kolejki i zapisuje jego treść na ekranie.

#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

Uwagi

W przypadku używania powiadomienia o zdarzeniach do asynchronicznego odbierania komunikatów z kolejki należy utworzyć metodę, która obsługuje przetwarzanie komunikatów. Kod musi wywołać BeginReceive metodę , aby rozpocząć przetwarzanie asynchroniczne. Po odebraniu komunikatu aplikacja jest powiadamiana za pośrednictwem ReceiveCompleted zdarzenia. Wystąpienie klasy jest przekazywane do delegata ReceiveCompletedEventArgs zdarzeń, który wywołuje procedurę obsługi zdarzeń. Dane skojarzone ze zdarzeniem ReceiveCompleted są zawarte w parametrze delegata AsyncResult .

Istnieją dwa sposoby dostarczania powiadomień o zakończeniu zdarzenia: powiadomienia o zdarzeniach i wywołania zwrotne. ReceiveCompletedEventArgs jest używany tylko z powiadomieniem o zdarzeniu. Aby uzyskać informacje dotyczące porównywania wywołań zwrotnych i powiadomień o zdarzeniach, zobacz "Zdarzenia a wywołania zwrotne" w witrynie MSDN.

ReceiveCompletedEventArgs zapewnia dostęp do komunikatu, który zainicjował koniec asynchronicznej operacji odbierania za pośrednictwem elementu Message członkowskiego. Jest to alternatywny dostęp do wiadomości i zachowuje się tak samo jak wywołanie metody MessageQueue.EndReceive.

Właściwości

AsyncResult

Pobiera lub ustawia wynik żądanej operacji asynchronicznej.

Message

Pobiera komunikat skojarzony z asynchroniczną operacją odbierania.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też