MessageQueue.BeginPeek 메서드

정의

메시지 큐가 메시지 피킹(peeking)을 시작하도록 한 후, 작업을 마치면 이벤트 처리기에 알리도록 하여 비동기 피킹(peeking) 작업을 시작합니다.

오버로드

BeginPeek(TimeSpan, Object, AsyncCallback)

시간 제한 및 상태 개체가 지정되어 있는 비동기 피킹(peeking) 작업을 시작합니다. 이는 작업의 수명이 지속되는 동안 관련된 정보를 제공합니다. 이 오버로드는 콜백을 통해 해당 작업의 이벤트 처리기 ID에 대한 알림을 수신합니다. 큐에서 메시지를 사용할 수 있거나 시간 초과가 발생할 때까지 작업이 완료되지 않습니다.

BeginPeek(TimeSpan, Object)

시간 제한 및 상태 개체가 지정되어 있는 비동기 피킹(peeking) 작업을 시작합니다. 이는 작업의 수명이 지속되는 동안 관련된 정보를 제공합니다. 큐에서 메시지를 사용할 수 있거나 시간 초과가 발생할 때까지 작업이 완료되지 않습니다.

BeginPeek(TimeSpan, Cursor, PeekAction, Object, AsyncCallback)

지정된 제한 시간이 있고 지정된 커서, 지정된 피킹(peeking) 작업 및 지정된 상태 개체를 사용하는 비동기 피킹(peeking) 작업을 초기화합니다. 상태 개체는 전체 작업 기간 동안 관련 정보를 제공합니다. 이 오버로드는 콜백을 통해 해당 작업의 이벤트 처리기 ID에 대한 알림을 수신합니다. 큐에서 메시지를 사용할 수 있거나 시간 초과가 발생할 때까지 작업이 완료되지 않습니다.

BeginPeek()

시간 제한이 없는 비동기 피킹(peeking) 작업을 시작합니다. 큐에서 메시지를 사용할 수 있을 때까지 작업이 완료되지 않습니다.

BeginPeek(TimeSpan)

지정된 시간 제한이 있는 비동기 피킹(peeking) 작업을 시작합니다. 큐에서 메시지를 사용할 수 있거나 시간이 초과될 때까지 작업이 완료되지 않습니다.

BeginPeek(TimeSpan, Object, AsyncCallback)

시간 제한 및 상태 개체가 지정되어 있는 비동기 피킹(peeking) 작업을 시작합니다. 이는 작업의 수명이 지속되는 동안 관련된 정보를 제공합니다. 이 오버로드는 콜백을 통해 해당 작업의 이벤트 처리기 ID에 대한 알림을 수신합니다. 큐에서 메시지를 사용할 수 있거나 시간 초과가 발생할 때까지 작업이 완료되지 않습니다.

public:
 IAsyncResult ^ BeginPeek(TimeSpan timeout, System::Object ^ stateObject, AsyncCallback ^ callback);
public IAsyncResult BeginPeek (TimeSpan timeout, object stateObject, AsyncCallback callback);
member this.BeginPeek : TimeSpan * obj * AsyncCallback -> IAsyncResult
Public Function BeginPeek (timeout As TimeSpan, stateObject As Object, callback As AsyncCallback) As IAsyncResult

매개 변수

timeout
TimeSpan

메시지를 사용할 수 있을 때까지 기다리는 시간 간격을 나타내는 TimeSpan입니다.

stateObject
Object

비동기 작업과 관련된 정보가 들어 있는 상태 개체이며 애플리케이션에서 지정합니다.

callback
AsyncCallback

비동기 작업 완료에 대한 알림을 수신할 AsyncCallback입니다.

반환

게시된 비동기 요청을 식별하는 IAsyncResult 입니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우

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

예제

다음 코드 예제에서는 비동기 피킹 작업을 만듭니다. 이 코드 예제에서는 로컬 메시지 큐에 메시지를 보낸 다음 를 호출하여 을 전달BeginPeek(TimeSpan, Object, AsyncCallback)합니다. 시간 제한 값은 10초, 특정 메시지를 식별하는 고유 정수, 이벤트 처리기를 MyPeekCompleted식별하는 의 AsyncCallback 새 instance. PeekCompleted 이벤트가 발생하면 이벤트 처리기가 메시지를 피킹하고 메시지 본문과 정수 메시지 식별자를 화면에 씁니다.

#using <System.Messaging.dll>
#using <System.dll>

using namespace System;
using namespace System::Messaging;

// Creates a new queue.
void CreateQueue(String^ queuePath, bool transactional)
{
    if(!MessageQueue::Exists(queuePath))
    {
        MessageQueue^ queue = MessageQueue::Create(queuePath, transactional);
        queue->Close();      
    }
    else
    {
        Console::WriteLine("{0} already exists.", queuePath);
    }
}

// Provides an event handler for the PeekCompleted event.
void MyPeekCompleted(IAsyncResult^ asyncResult)
{
    // Connect to the queue.
    MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");

    // End the asynchronous peek operation.
    Message^ msg = queue->EndPeek(asyncResult);

    // Display the message information on the screen.
    Console::WriteLine("Message number: {0}", asyncResult->AsyncState);
    Console::WriteLine("Message body: {0}", msg->Body);

    // Receive the message. This will remove the message from the queue.
    msg = queue->Receive(TimeSpan::FromSeconds(10.0));

    queue->Close();
}

int main()
{
    // Represents a state object associated with each message.
    int messageNumber = 0;

    // Create a non-transactional queue on the local computer.
    // Note that the queue might not be immediately accessible, and
    // therefore this example might throw an exception of type
    // System.Messaging.MessageQueueException when trying to send a
    // message to the newly created queue.
    CreateQueue(".\\exampleQueue", false);

    // Connect to a queue on the local computer.
    MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");

    // Send a message to the queue.
    queue->Send("Example Message");

    // Begin the asynchronous peek operation.
    queue->BeginPeek(TimeSpan::FromSeconds(10.0), messageNumber++,
        gcnew AsyncCallback(MyPeekCompleted));

    // Simulate doing other work on the current thread.
    System::Threading::Thread::Sleep(TimeSpan::FromSeconds(10.0));

    queue->Close();
}
using System;
using System.Messaging;

public class QueueExample
{
    // Represents a state object associated with each message.
    static int messageNumber = 0;

    public static void Main()
    {
        // Create a non-transactional queue on the local computer.
        // Note that the queue might not be immediately accessible, and
        // therefore this example might throw an exception of type
        // System.Messaging.MessageQueueException when trying to send a
        // message to the newly created queue.
        CreateQueue(".\\exampleQueue", false);

        // Connect to a queue on the local computer.
        MessageQueue queue = new MessageQueue(".\\exampleQueue");

        // Send a message to the queue.
        queue.Send("Example Message");

        // Begin the asynchronous peek operation.
        queue.BeginPeek(TimeSpan.FromSeconds(10.0), messageNumber++,
            new AsyncCallback(MyPeekCompleted));

        // Simulate doing other work on the current thread.
        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10.0));

        return;
    }

    // Creates a new queue.
    public static void CreateQueue(string queuePath, bool transactional)
    {
        if(!MessageQueue.Exists(queuePath))
        {
            MessageQueue.Create(queuePath, transactional);
        }
        else
        {
            Console.WriteLine(queuePath + " already exists.");
        }
    }

    // Provides an event handler for the PeekCompleted event.
    private static void MyPeekCompleted(IAsyncResult asyncResult)
    {
        // Connect to the queue.
        MessageQueue queue = new MessageQueue(".\\exampleQueue");

        // End the asynchronous peek operation.
        Message msg = queue.EndPeek(asyncResult);

        // Display the message information on the screen.
        Console.WriteLine("Message number: {0}", (int)asyncResult.AsyncState);
        Console.WriteLine("Message body: {0}", (string)msg.Body);

        // Receive the message. This will remove the message from the queue.
        msg = queue.Receive(TimeSpan.FromSeconds(10.0));
    }
}

설명

이 오버로드를 사용하면 큐에서 메시지를 사용할 수 있게 되거나 지정된 시간 간격이 만료될 때 콜백 매개 변수에 지정된 콜백이 직접 호출됩니다. PeekCompleted 이벤트가 발생하지 않습니다. 의 BeginPeek 다른 오버로드는 이 구성 요소를 사용하여 이벤트를 발생합니다 PeekCompleted .

PeekCompleted 메시지가 큐에 이미 있는 경우에도 발생합니다.

메서드는 BeginPeek 즉시 반환되지만 이벤트 처리기가 호출될 때까지 비동기 작업이 완료되지 않습니다.

BeginPeek 는 비동기이므로 현재 실행 스레드를 차단하지 않고 큐를 피킹하기 위해 호출할 수 있습니다. 큐를 동기적으로 피킹하려면 메서드를 Peek 사용합니다.

비동기 작업이 완료되면 이벤트 처리기에서 또는 BeginReceive 를 다시 호출 BeginPeek 하여 알림을 계속 받을 수 있습니다.

BeginPeekIAsyncResult 는 메서드가 시작된 비동기 작업을 식별하는 을 반환합니다. 일반적으로 가 호출될 때까지 EndPeek(IAsyncResult) 는 사용하지 않지만 작업 수명 동안 이 IAsyncResult 기능을 사용할 수 있습니다. 그러나 여러 비동기 작업을 시작하는 경우 해당 값을 배열에 배치 IAsyncResult 하고 모든 작업 또는 작업이 완료되기를 기다릴지 여부를 지정할 수 있습니다. 이 경우 의 IAsyncResult 속성을 사용하여 AsyncWaitHandle 완료된 작업을 식별합니다.

상태 개체는 작업과 상태 정보를 연결합니다. 예를 들어 여러 작업을 시작하기 위해 여러 번 호출 BeginPeek 하는 경우 정의한 별도의 상태 개체를 통해 각 작업을 식별할 수 있습니다.

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

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

추가 정보

적용 대상

BeginPeek(TimeSpan, Object)

시간 제한 및 상태 개체가 지정되어 있는 비동기 피킹(peeking) 작업을 시작합니다. 이는 작업의 수명이 지속되는 동안 관련된 정보를 제공합니다. 큐에서 메시지를 사용할 수 있거나 시간 초과가 발생할 때까지 작업이 완료되지 않습니다.

public:
 IAsyncResult ^ BeginPeek(TimeSpan timeout, System::Object ^ stateObject);
public IAsyncResult BeginPeek (TimeSpan timeout, object stateObject);
member this.BeginPeek : TimeSpan * obj -> IAsyncResult
Public Function BeginPeek (timeout As TimeSpan, stateObject As Object) As IAsyncResult

매개 변수

timeout
TimeSpan

메시지를 사용할 수 있을 때까지 기다리는 시간 간격을 나타내는 TimeSpan입니다.

stateObject
Object

비동기 작업과 관련된 정보가 들어 있는 상태 개체이며 애플리케이션에서 지정합니다.

반환

게시된 비동기 요청을 식별하는 IAsyncResult 입니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우

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

예제

다음 코드 예제에서는 큐 경로 ".\myQueue"를 사용하여 비동기 피킹 작업을 만듭니다. 이벤트 처리기 를 MyPeekCompleted만들고 이벤트 처리기 대리자에게 PeekCompleted 연결합니다. BeginPeek 는 1분의 시간 제한으로 호출됩니다. 에 대한 BeginPeek 각 호출에는 해당 특정 작업을 식별하는 고유한 연결된 정수가 있습니다. PeekCompleted 이벤트가 발생하거나 제한 시간이 만료되면 메시지가 있는 경우 검색되고 해당 본문과 작업별 정수 식별자가 화면에 기록됩니다. 그런 다음 BeginPeek 다시 호출되어 동일한 시간 제한 및 방금 완료된 작업의 연결된 정수로 새 비동기 피킹 작업을 시작합니다.

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

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   // Represents a state object associated with each message.
   static int messageNumber = 0;

   // Provides an event handler for the PeekCompleted
   // event.
   //
   static void MyPeekCompleted( Object^ source, PeekCompletedEventArgs^ asyncResult )
   {
      try
      {
         // 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, 
         // including the message number (state object).
         Console::WriteLine( "Message: {0} {1}", asyncResult->AsyncResult->AsyncState, static_cast<String^>(m->Body) );

         // Restart the asynchronous peek operation, with the 
         // same time-out.
         mq->BeginPeek( TimeSpan(0,1,0), messageNumber++ );
      }
      catch ( MessageQueueException^ e ) 
      {
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
         {
            Console::WriteLine( e );
         }

         // Handle other sources of MessageQueueException.
      }

      // Handle other exceptions.
      return;
   }
};


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

   // Begin the asynchronous peek operation with a timeout 
   // of one minute.
   myQueue->BeginPeek( TimeSpan(0,1,0), MyNewQueue::messageNumber++ );

   // 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 MyNewQueue3
    {
        // Represents a state object associated with each message.
        static int messageNumber = 0;

        //**************************************************
        // 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 with a time-out
            // of one minute.
            myQueue.BeginPeek(new TimeSpan(0, 1, 0), messageNumber++);

            // Do other work on the current thread.

            return;
        }

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

        private static void MyPeekCompleted(Object source,
            PeekCompletedEventArgs asyncResult)
        {
            try
            {
                // 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,
                // including the message number (state object).
                Console.WriteLine("Message: " +
                    (int)asyncResult.AsyncResult.AsyncState + " "
                    + (string)m.Body);

                // Restart the asynchronous peek operation, with the
                // same time-out.
                mq.BeginPeek(new TimeSpan(0, 1, 0), messageNumber++);
            }

            catch (MessageQueueException e)
            {
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.IOTimeout)
                {
                    Console.WriteLine(e.ToString());
                }

                // Handle other sources of MessageQueueException.
            }

            // Handle other exceptions.

            return;
        }
    }
}
Imports System.Messaging


   
' Provides a container class for the example.

Public Class MyNewQueue

        ' Represents a state object associated with each message.
        Private Shared messageNumber As Integer = 0



        ' 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 with a time-out 
            ' of one minute.
            myQueue.BeginPeek(New TimeSpan(0, 1, 0), messageNumber)
            messageNumber += 1

            ' 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)

            Try
                ' 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, 
                ' including(the) message number (state object).
                Console.WriteLine(("Message: " + _
                    CInt(asyncResult.AsyncResult.AsyncState) + _
                    " " + CStr(m.Body)))

                ' Restart the asynchronous peek operation, with the 
                ' same time-out.
                mq.BeginPeek(New TimeSpan(0, 1, 0), messageNumber)
                messageNumber += 1


            Catch e As MessageQueueException

                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.IOTimeout Then

                    Console.WriteLine(e.ToString())

                    ' Handle other sources of MessageQueueException.

                End If

                ' Handle other exceptions.

            End Try

            Return

        End Sub

End Class

설명

비동기 처리에서는 를 사용하여 BeginPeek 큐에서 메시지를 사용할 수 있게 되거나 지정된 시간 간격이 만료될 때 이벤트를 발생 PeekCompleted 합니다.

PeekCompleted 메시지가 큐에 이미 있는 경우에도 발생합니다.

이 오버로드를 사용하여 작업의 수명 동안 유지되는 작업과 정보를 연결합니다. 이벤트 처리기는 작업과 연결된 의 IAsyncResult 속성을 확인 AsyncState 하여 이 정보에 액세스할 수 있습니다.

를 사용 BeginPeek하려면 비동기 작업의 결과를 처리하는 이벤트 처리기를 만들고 이벤트 대리자와 연결합니다. BeginPeek 는 비동기 피킹 작업을 시작합니다. MessageQueue 는 메시지가 큐에 도착하면 이벤트를 발생 PeekCompleted 시 알림을 받습니다. 그런 다음 를 MessageQueue 호출 EndPeek(IAsyncResult) 하거나 를 사용하여 PeekCompletedEventArgs결과를 검색하여 메시지에 액세스할 수 있습니다.

메서드는 BeginPeek 즉시 반환되지만 이벤트 처리기가 호출될 때까지 비동기 작업이 완료되지 않습니다.

BeginPeek 는 비동기이므로 현재 실행 스레드를 차단하지 않고 큐를 피킹하기 위해 호출할 수 있습니다. 큐를 동기적으로 피킹하려면 메서드를 Peek 사용합니다.

비동기 작업이 완료되면 이벤트 처리기에서 또는 BeginReceive 를 다시 호출 BeginPeek 하여 알림을 계속 받을 수 있습니다.

BeginPeekIAsyncResult 는 메서드가 시작된 비동기 작업을 식별하는 을 반환합니다. 일반적으로 가 호출될 때까지 EndPeek(IAsyncResult) 는 사용하지 않지만 작업 수명 동안 이 IAsyncResult 기능을 사용할 수 있습니다. 그러나 여러 비동기 작업을 시작하는 경우 해당 값을 배열에 배치 IAsyncResult 하고 모든 작업 또는 작업이 완료되기를 기다릴지 여부를 지정할 수 있습니다. 이 경우 의 IAsyncResult 속성을 사용하여 AsyncWaitHandle 완료된 작업을 식별합니다.

이 오버로드는 시간 제한 및 상태 개체를 지정합니다. 매개 변수에 지정된 간격이 timeout 만료되면 이 구성 요소는 이벤트를 발생합니다 PeekCompleted . 메시지가 없으므로 에 대한 후속 호출 EndPeek(IAsyncResult) 은 예외를 throw합니다.

상태 개체는 작업과 상태 정보를 연결합니다. 예를 들어 여러 작업을 시작하기 위해 여러 번 호출 BeginPeek 하는 경우 정의한 별도의 상태 개체를 통해 각 작업을 식별할 수 있습니다. 이 시나리오에 대한 일러스트레이션은 예제 섹션을 참조하세요.

상태 개체를 사용하여 프로세스 스레드 간에 정보를 전달할 수도 있습니다. 스레드가 시작되었지만 콜백이 비동기 시나리오에서 다른 스레드에 있는 경우 상태 개체가 마샬링되고 이벤트의 정보와 함께 다시 전달됩니다.

이 이falseCanRead 완료 이벤트가 발생하지만 를 호출EndPeek(IAsyncResult)할 때 예외가 throw됩니다.

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

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

추가 정보

적용 대상

BeginPeek(TimeSpan, Cursor, PeekAction, Object, AsyncCallback)

지정된 제한 시간이 있고 지정된 커서, 지정된 피킹(peeking) 작업 및 지정된 상태 개체를 사용하는 비동기 피킹(peeking) 작업을 초기화합니다. 상태 개체는 전체 작업 기간 동안 관련 정보를 제공합니다. 이 오버로드는 콜백을 통해 해당 작업의 이벤트 처리기 ID에 대한 알림을 수신합니다. 큐에서 메시지를 사용할 수 있거나 시간 초과가 발생할 때까지 작업이 완료되지 않습니다.

public:
 IAsyncResult ^ BeginPeek(TimeSpan timeout, System::Messaging::Cursor ^ cursor, System::Messaging::PeekAction action, System::Object ^ state, AsyncCallback ^ callback);
public IAsyncResult BeginPeek (TimeSpan timeout, System.Messaging.Cursor cursor, System.Messaging.PeekAction action, object state, AsyncCallback callback);
member this.BeginPeek : TimeSpan * System.Messaging.Cursor * System.Messaging.PeekAction * obj * AsyncCallback -> IAsyncResult
Public Function BeginPeek (timeout As TimeSpan, cursor As Cursor, action As PeekAction, state As Object, callback As AsyncCallback) As IAsyncResult

매개 변수

timeout
TimeSpan

메시지를 사용할 수 있을 때까지 기다리는 시간 간격을 나타내는 TimeSpan입니다.

cursor
Cursor

메시지 큐에서 특정 위치를 유지하는 Cursor입니다.

action
PeekAction

PeekAction 값 중 하나입니다. 이 값은 큐의 현재 메시지를 피킹할지 또는 다음 메시지를 피킹할지 여부를 나타냅니다.

state
Object

비동기 작업과 관련된 정보가 들어 있는 상태 개체이며 애플리케이션에서 지정합니다.

callback
AsyncCallback

비동기 작업 완료에 대한 알림을 수신하는 AsyncCallback입니다.

반환

게시된 비동기 요청을 식별하는 IAsyncResult 입니다.

예외

action 매개 변수에 대해 PeekAction.Current 또는 PeekAction.Next 이외의 값을 지정했습니다.

cursor 매개 변수가 null인 경우

timeout 매개 변수에 지정된 값이 잘못된 경우

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

설명

이 오버로드를 사용하는 경우 큐에서 메시지를 사용할 수 있게 되거나 지정된 시간 간격이 만료될 때 콜백 매개 변수에 지정된 콜백이 직접 호출됩니다. PeekCompleted 이벤트가 발생하지 않습니다. 의 BeginPeek 다른 오버로드는 이 구성 요소를 사용하여 이벤트를 발생합니다 PeekCompleted .

PeekCompleted 는 큐에 메시지가 이미 있는 경우에도 발생합니다.

메서드는 BeginPeek 즉시 반환되지만 이벤트 처리기가 호출될 때까지 비동기 작업이 완료되지 않습니다.

BeginPeek 는 비동기이므로 현재 실행 스레드를 차단하지 않고 큐를 피킹하도록 호출할 수 있습니다. 큐를 동기적으로 피킹하려면 메서드를 Peek 사용합니다.

비동기 작업이 완료되면 이벤트 처리기에서 또는 BeginReceive 다시 호출 BeginPeek 하여 알림을 계속 받을 수 있습니다.

BeginPeekIAsyncResult 메서드에서 시작한 비동기 작업을 식별하는 을 반환합니다. 일반적으로 가 호출될 때까지 EndPeek(IAsyncResult) 는 사용하지 않지만 작업의 수명 동안 사용할 IAsyncResult 수 있습니다. 그러나 여러 비동기 작업을 시작하는 경우 해당 값을 배열에 배치 IAsyncResult 하고 모든 작업 또는 작업이 완료되기를 기다릴지 여부를 지정할 수 있습니다. 이 경우 의 속성을 IAsyncResult 사용하여 AsyncWaitHandle 완료된 작업을 식별합니다.

상태 개체는 작업과 상태 정보를 연결합니다. 예를 들어 여러 작업을 시작하기 위해 여러 번 호출 BeginPeek 하는 경우 정의하는 별도의 상태 개체를 통해 각 작업을 식별할 수 있습니다.

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

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

추가 정보

적용 대상

BeginPeek()

시간 제한이 없는 비동기 피킹(peeking) 작업을 시작합니다. 큐에서 메시지를 사용할 수 있을 때까지 작업이 완료되지 않습니다.

public:
 IAsyncResult ^ BeginPeek();
public IAsyncResult BeginPeek ();
member this.BeginPeek : unit -> IAsyncResult
Public Function BeginPeek () As IAsyncResult

반환

게시된 비동기 요청을 식별하는 IAsyncResult 입니다.

예외

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

예제

다음 코드 예제에서는 라는 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

설명

비동기 처리에서는 를 사용하여 BeginPeek 큐에서 PeekCompleted 메시지를 사용할 수 있게 되면 이벤트를 발생합니다.

PeekCompleted 는 큐에 메시지가 이미 있는 경우에도 발생합니다.

를 사용 BeginPeek하려면 비동기 작업의 결과를 처리하고 이벤트 대리자와 연결하는 이벤트 처리기를 만듭니다. BeginPeek 는 비동기 피킹 작업을 시작합니다. 는 MessageQueue 메시지가 큐에 도착할 때 이벤트 발생 PeekCompleted 을 통해 알림을 받습니다. 그런 다음 를 MessageQueue 호출 EndPeek(IAsyncResult) 하거나 를 사용하여 PeekCompletedEventArgs결과를 검색하여 메시지에 액세스할 수 있습니다.

메서드는 BeginPeek 즉시 반환되지만 이벤트 처리기가 호출될 때까지 비동기 작업이 완료되지 않습니다.

BeginPeek 는 비동기이므로 현재 실행 스레드를 차단하지 않고 큐를 피킹하도록 호출할 수 있습니다. 큐를 동기적으로 피킹하려면 메서드를 Peek 사용합니다.

비동기 작업이 완료되면 이벤트 처리기에서 또는 BeginReceive 다시 호출 BeginPeek 하여 알림을 계속 받을 수 있습니다.

를 반환하는 BeginPeekIAsyncResult 메서드가 시작한 비동기 작업을 식별합니다. 일반적으로 가 호출될 때까지 EndPeek(IAsyncResult) 는 사용하지 않지만 작업의 수명 동안 사용할 IAsyncResult 수 있습니다. 그러나 여러 비동기 작업을 시작하는 경우 해당 값을 배열에 배치 IAsyncResult 하고 모든 작업 또는 작업이 완료되기를 기다릴지 여부를 지정할 수 있습니다. 이 경우 의 속성을 IAsyncResult 사용하여 AsyncWaitHandle 완료된 작업을 식별합니다.

가 이falseCanRead 완료 이벤트가 발생하지만 를 호출EndPeek(IAsyncResult)할 때 예외가 throw됩니다.

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

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

추가 정보

적용 대상

BeginPeek(TimeSpan)

지정된 시간 제한이 있는 비동기 피킹(peeking) 작업을 시작합니다. 큐에서 메시지를 사용할 수 있거나 시간이 초과될 때까지 작업이 완료되지 않습니다.

public:
 IAsyncResult ^ BeginPeek(TimeSpan timeout);
public IAsyncResult BeginPeek (TimeSpan timeout);
member this.BeginPeek : TimeSpan -> IAsyncResult
Public Function BeginPeek (timeout As TimeSpan) As IAsyncResult

매개 변수

timeout
TimeSpan

메시지를 사용할 수 있을 때까지 기다리는 시간 간격을 나타내는 TimeSpan입니다.

반환

게시된 비동기 요청을 식별하는 IAsyncResult 입니다.

예외

timeout 매개 변수에 지정된 값이 잘못된 경우

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

예제

다음 코드 예제에서는 큐 경로 ".\myQueue"를 사용하여 비동기 피킹 작업을 만듭니다. 이벤트 처리기 를 MyPeekCompleted만들고 이벤트 처리기 대리자에게 PeekCompleted 연결합니다. BeginPeek 는 비동기 피킹 작업을 시작하기 위해 1분의 시간 제한으로 호출됩니다. PeekCompleted 이벤트가 발생하거나 시간 초과가 만료되면 메시지가 있으면 검색되고 해당 본문이 화면에 기록됩니다. 그런 다음 BeginPeek 다시 호출되어 동일한 시간 제한으로 새 비동기 피킹 작업을 시작합니다.

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

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:
   static void MyPeekCompleted( Object^ source, PeekCompletedEventArgs^ asyncResult )
   {      try
      {
         // 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, with the 
         // same time-out.
         mq->BeginPeek( TimeSpan(0,1,0) );
      }
      catch ( MessageQueueException^ e ) 
      {
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
         {
            Console::WriteLine( e );
         }

         // Handle other sources of MessageQueueException.
      }

      // Handle other exceptions.
      return;
   }
};

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 with a timeout 
   // of one minute.
   myQueue->BeginPeek( TimeSpan(0,1,0) );

   // 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 MyNewQueue2
    {
        //**************************************************
        // 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 with a time-out
            // of one minute.
            myQueue.BeginPeek(new TimeSpan(0, 1, 0));

            // Do other work on the current thread.

            return;
        }

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

        private static void MyPeekCompleted(Object source,
            PeekCompletedEventArgs asyncResult)
        {
            try
            {
                // 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, with the
                // same time-out.
                mq.BeginPeek(new TimeSpan(0, 1, 0));
            }

            catch (MessageQueueException e)
            {
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.IOTimeout)
                {
                    Console.WriteLine(e.ToString());
                }

                // Handle other sources of MessageQueueException.
            }

            // Handle other exceptions.

            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 with a time-out 
            ' of one minute.
            myQueue.BeginPeek(New TimeSpan(0, 1, 0))

            ' 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)

            Try
                ' 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, with the 
                ' same time-out.
                mq.BeginPeek(New TimeSpan(0, 1, 0))

            Catch e As MessageQueueException

                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.IOTimeout Then

                    Console.WriteLine(e.ToString())

                    ' Handle other sources of MessageQueueException.
                End If

                ' Handle other exceptions.

            End Try

            Return

        End Sub

End Class

설명

비동기 처리에서는 를 사용하여 BeginPeek 큐에서 메시지를 사용할 수 있게 되거나 지정된 시간 간격이 만료된 경우 이벤트를 발생 PeekCompleted 합니다.

PeekCompleted 는 큐에 메시지가 이미 있는 경우에도 발생합니다.

를 사용 BeginPeek하려면 비동기 작업의 결과를 처리하고 이벤트 대리자와 연결하는 이벤트 처리기를 만듭니다. BeginPeek 는 비동기 피킹 작업을 시작합니다. 는 MessageQueue 메시지가 큐에 도착할 때 이벤트 발생 PeekCompleted 을 통해 알림을 받습니다. 그런 다음 를 MessageQueue 호출 EndPeek(IAsyncResult) 하거나 를 사용하여 PeekCompletedEventArgs결과를 검색하여 메시지에 액세스할 수 있습니다.

메서드는 BeginPeek 즉시 반환되지만 이벤트 처리기가 호출될 때까지 비동기 작업이 완료되지 않습니다.

BeginPeek 는 비동기이므로 현재 실행 스레드를 차단하지 않고 큐를 피킹하도록 호출할 수 있습니다. 큐를 동기적으로 피킹하려면 메서드를 Peek 사용합니다.

비동기 작업이 완료되면 이벤트 처리기에서 또는 BeginReceive 다시 호출 BeginPeek 하여 알림을 계속 받을 수 있습니다.

를 반환하는 BeginPeekIAsyncResult 메서드가 시작한 비동기 작업을 식별합니다. 일반적으로 가 호출될 때까지 EndPeek(IAsyncResult) 는 사용하지 않지만 작업의 수명 동안 사용할 IAsyncResult 수 있습니다. 그러나 여러 비동기 작업을 시작하는 경우 해당 값을 배열에 배치 IAsyncResult 하고 모든 작업 또는 작업이 완료되기를 기다릴지 여부를 지정할 수 있습니다. 이 경우 의 IAsyncResult 속성을 사용하여 AsyncWaitHandle 완료된 작업을 식별합니다.

이 오버로드는 시간 초과를 지정합니다. 매개 변수에 지정된 간격이 timeout 만료되면 이 구성 요소는 이벤트를 발생합니다 PeekCompleted . 메시지가 없으므로 에 대한 후속 호출 EndPeek(IAsyncResult) 은 예외를 throw합니다.

이 이falseCanRead 완료 이벤트가 발생하지만 를 호출EndPeek(IAsyncResult)할 때 예외가 throw됩니다.

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

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

추가 정보

적용 대상

스레드 보안

메서드는 스레드로부터 안전하지 않습니다.