MessageQueue.EndPeek(IAsyncResult) 메서드

정의

지정된 비동기 피킹(peeking) 작업을 완료합니다.

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

매개 변수

asyncResult
IAsyncResult

IAsyncResult는 종료한 후 최종 결과를 검색해 올 비동기 피킹(peeking) 작업을 식별합니다.

반환

완료된 비동기 작업과 관련된 Message를 반환합니다.

예외

asyncResult 매개 변수가 null인 경우

asyncResult 매개 변수의 구문이 잘못된 경우.

메시지 큐 메서드에 액세스하는 동안 오류가 발생한 경우

예제

다음 코드 예제에서는 라는 MyPeekCompleted이벤트 처리기를 만들고, 이벤트 처리기 대리자에게 연결 PeekCompleted 하고, 를 호출 BeginPeek 하여 경로 ".\myQueue"에 있는 큐에서 비동기 피킹 작업을 시작합니다. PeekCompleted 이벤트가 발생하면 예제에서는 메시지를 피킹하고 해당 본문을 화면에 씁니다. 그런 다음, 이 예제에서는 를 다시 호출 BeginPeek 하여 새 비동기 피킹 작업을 시작합니다.

#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

설명

PeekCompleted 이벤트가 발생하면 EndPeek(IAsyncResult) 호출에 의해 BeginPeek 시작된 작업을 완료합니다. 이렇게 EndPeek(IAsyncResult) 하려면 메시지를 피킹합니다.

BeginPeek 는 시간 초과를 지정할 수 있으며, 이로 인해 PeekCompleted 큐에 메시지가 표시되기 전에 시간 초과가 발생하면 이벤트가 발생합니다. 큐에 메시지가 도착하지 않고 시간 초과가 발생하면 후속 호출 EndPeek(IAsyncResult) 에서 예외를 throw합니다.

EndPeek(IAsyncResult) 는 이벤트를 발생 PeekCompleted 시킨 메시지를 읽는 데 사용됩니다.

메시지를 비동기적으로 피킹하려면 를 호출한 후 를 다시 호출 BeginPeekEndPeek(IAsyncResult)할 수 있습니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름 Yes

적용 대상

추가 정보