PeekCompletedEventArgs Classe

Definizione

Fornisce dati per l'evento PeekCompleted.Provides data for the PeekCompleted event. Quando l'operazione di visualizzazione asincrona chiama un gestore eventi, un'istanza di questa classe viene passata al gestore.When your asynchronous peek operation calls an event handler, an instance of this class is passed to the handler.

public ref class PeekCompletedEventArgs : EventArgs
public class PeekCompletedEventArgs : EventArgs
type PeekCompletedEventArgs = class
    inherit EventArgs
Public Class PeekCompletedEventArgs
Inherits EventArgs
Ereditarietà
PeekCompletedEventArgs

Esempi

L'esempio di codice seguente crea un gestore eventi per PeekCompleted l'evento e lo associa al delegato dell'evento PeekCompletedEventHandlerusando.The following code example creates an event handler for the PeekCompleted event and associates it with the event delegate by using the PeekCompletedEventHandler. Il gestore eventi, MyPeekCompleted, Visualizza un messaggio e scrive la relativa etichetta sullo schermo.The event handler, MyPeekCompleted, peeks a message and writes its label to the screen.

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

using namespace System;
using namespace System::Messaging;

// This example performs asynchronous peek operation
// processing.
//*************************************************
ref class MyNewQueue
{
public:

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

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

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

      // Restart the asynchronous peek operation.
      mq->BeginPeek();
      return;
   }
};

// Provides an entry point into the application.
//         
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 PeekCompleted event.
   myQueue->PeekCompleted += gcnew PeekCompletedEventHandler( MyNewQueue::MyPeekCompleted );

   // Begin the asynchronous peek operation.
   myQueue->BeginPeek();

   // 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 peek 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 PeekCompleted event.
            myQueue.PeekCompleted += new 
                PeekCompletedEventHandler(MyPeekCompleted);
            
            // Begin the asynchronous peek operation.
            myQueue.BeginPeek();
            
            // Do other work on the current thread.

            return;
        }


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

            // End the asynchronous peek operation.
            Message m = mq.EndPeek(asyncResult.AsyncResult);

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

            // Restart the asynchronous peek operation.
            mq.BeginPeek();
            
            return; 
        }
    }
}
Imports System.Messaging





' Provides a container class for the example.
Public Class MyNewQueue



        ' Provides an entry point into the application.
        '		 
        ' This example performs asynchronous peek 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 PeekCompleted event.
            AddHandler myQueue.PeekCompleted, AddressOf _
                MyPeekCompleted

            ' Begin the asynchronous peek operation.
            myQueue.BeginPeek()

            ' Do other work on the current thread.
            Return
        End Sub


        '**************************************************
        ' Provides an event handler for the PeekCompleted
        ' event.
        '**************************************************

        Private Shared Sub MyPeekCompleted(ByVal [source] As _
            [Object], ByVal asyncResult As PeekCompletedEventArgs)

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

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

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

            ' Restart the asynchronous peek operation.
            mq.BeginPeek()

            Return

        End Sub

End Class

Commenti

Quando si utilizza la notifica degli eventi per visualizzare (leggere senza rimuovere) i messaggi in modo asincrono dalla coda, è necessario creare un metodo che gestisce l'elaborazione del messaggio.When you use event notification to peek (read without removing) messages asynchronously from the queue, you must create a method that handles your message processing. Il codice deve chiamare BeginPeek per iniziare l'elaborazione asincrona.Your code must call BeginPeek to begin the asynchronous processing. Quando viene visualizzato un messaggio, l'applicazione riceve una notifica tramite l' PeekCompleted evento.When a message is peeked, your application is notified through the PeekCompleted event. Un'istanza di PeekCompletedEventArgs viene passata al delegato dell'evento che chiama il gestore eventi.An instance of PeekCompletedEventArgs is passed into the event delegate that calls your event handler. I dati associati PeekCompleted all'evento sono contenuti nel AsyncResult parametro del delegato.The data associated with the PeekCompleted event is contained in the delegate's AsyncResult parameter.

Esistono due modi per fornire la notifica del completamento dell'evento: la notifica degli eventi e i callback.There are two ways to provide notification of event completion: event notification and callbacks. PeekCompletedEventArgsviene utilizzato solo con la notifica degli eventi.PeekCompletedEventArgs is used only with event notification. Per informazioni sul confronto tra callback e notifica degli eventi, vedere "eventi e Callback "su MSDN.For information comparing callbacks and event notification, see "Events vs. Callbacks" on MSDN.

PeekCompletedEventArgsconsente di accedere al messaggio che ha avviato la fine dell'operazione di lettura asincrona tramite il Message membro.PeekCompletedEventArgs provides access to the message that initiated the end of the asynchronous peek operation, through the Message member. Si tratta di un accesso alternativo al messaggio e si comporta in modo molto simile a una chiamata a MessageQueue.EndPeek.This is an alternate access to the message, and behaves much the same as a call to MessageQueue.EndPeek.

Proprietà

AsyncResult

Ottiene o imposta i risultati dell'operazione asincrona richiesta.Gets or sets the result of the asynchronous operation requested.

Message

Ottiene il messaggio associato all'operazione di visualizzazione asincrona.Gets the message associated with the asynchronous peek operation.

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Ereditato da Object)

Si applica a

Vedi anche