MessageQueue.EndPeek(IAsyncResult) Methode

Definitie

Hiermee voltooit u de opgegeven asynchrone peekbewerking.

public:
 System::Messaging::Message ^ EndPeek(IAsyncResult ^ asyncResult);
public System.Messaging.Message EndPeek(IAsyncResult asyncResult);
member this.EndPeek : IAsyncResult -> System.Messaging.Message
Public Function EndPeek (asyncResult As IAsyncResult) As Message

Parameters

asyncResult
IAsyncResult

Hiermee IAsyncResult wordt de asynchrone peekbewerking geïdentificeerd die moet worden voltooid en waaruit een eindresultaat moet worden opgehaald.

Retouren

De Message gekoppelde aan de voltooide asynchrone bewerking.

Uitzonderingen

De asyncResult parameter is null.

De syntaxis van de asyncResult parameter is ongeldig.

Er is een fout opgetreden bij het openen van een Message Queuing-methode.

Voorbeelden

In het volgende codevoorbeeld wordt een gebeurtenishandler met de naam gemaakt MyPeekCompleted, gekoppeld aan de gemachtigde van de PeekCompleted gebeurtenis-handler en wordt aangeroepen BeginPeek om een asynchrone peek-bewerking te starten in de wachtrij die zich in het pad '.\myQueue' bevindt. Wanneer een PeekCompleted gebeurtenis wordt gegenereerd, wordt het bericht in het voorbeeld weergegeven en wordt de hoofdtekst naar het scherm geschreven. Het voorbeeld roept BeginPeek vervolgens opnieuw aan om een nieuwe asynchrone peek-bewerking te starten.

#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

Opmerkingen

Wanneer de PeekCompleted gebeurtenis wordt gegenereerd, EndPeek(IAsyncResult) voltooit u de bewerking die is gestart door de BeginPeek aanroep. U doet dit EndPeek(IAsyncResult) door het bericht te bekijken.

BeginPeek kan een time-out opgeven, waardoor de PeekCompleted gebeurtenis wordt gegenereerd als er een time-out optreedt voordat een bericht in de wachtrij wordt weergegeven. Wanneer er een time-out optreedt zonder dat er een bericht in de wachtrij binnenkomt, genereert een volgende aanroep om een uitzondering te EndPeek(IAsyncResult) genereren.

EndPeek(IAsyncResult) wordt gebruikt om het bericht te lezen waardoor de PeekCompleted gebeurtenis is gegenereerd.

Als u berichten asynchroon wilt blijven bekijken, kunt u opnieuw bellen BeginPeek na het bellen EndPeek(IAsyncResult).

In de volgende tabel ziet u of deze methode beschikbaar is in verschillende werkgroepmodi.

Werkgroepmodus Available
Lokale computer Ja
Naam van lokale computer en directe indeling Ja
Externe computer No
Naam van externe computer en directe indeling Ja

Van toepassing op

Zie ook