MessageQueue.EndPeek(IAsyncResult) Metoda

Definice

Dokončí zadanou asynchronní operaci náhledu.

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

Parametry

asyncResult
IAsyncResult

Tím IAsyncResult se identifikuje asynchronní operace náhledu, která se má dokončit a ze které se má načíst konečný výsledek.

Návraty

Přidružená Message k dokončené asynchronní operaci.

Výjimky

Parametr asyncResult je null.

Syntaxe parametru asyncResult není platná.

Při přístupu k metodě řízení front zpráv došlo k chybě.

Příklady

Následující příklad kódu vytvoří obslužnou rutinu události s názvem MyPeekCompleted, připojí ji k PeekCompleted delegátu obslužné rutiny události a volání BeginPeek inicializuje asynchronní náhled operace ve frontě, která je umístěna v cestě ".\myQueue". PeekCompleted Když je vyvolána událost, příklad zobrazí zprávu a zapíše její text na obrazovku. Příklad pak zavolá BeginPeek znovu, aby zahájil novou asynchronní náhledovou operaci.

#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

Poznámky

Při vyvolání PeekCompletedEndPeek(IAsyncResult) události dokončí operaci, kterou iniciovala BeginPeek volání. Uděláte to tak, že EndPeek(IAsyncResult) zobrazíte zprávu.

BeginPeek může určit časový limit, který způsobí PeekCompleted vyvolání události, pokud dojde k vypršení časového limitu před zobrazením zprávy ve frontě. Pokud dojde k vypršení časového limitu bez zprávy přicházející do fronty, následné volání vyvolá EndPeek(IAsyncResult) výjimku.

EndPeek(IAsyncResult) slouží ke čtení zprávy, která způsobila PeekCompleted vyvolání události.

Pokud chcete pokračovat asynchronně zobrazit zprávy, můžete znovu zavolat BeginPeek po volání EndPeek(IAsyncResult).

Následující tabulka ukazuje, zda je tato metoda k dispozici v různých režimech pracovní skupiny.

Režim pracovní skupiny Available
Místní počítač Yes
Název místního počítače a přímého formátu Yes
Vzdálený počítač No
Název vzdáleného počítače a přímého formátu Yes

Platí pro

Viz také