MessageQueue.EndPeek(IAsyncResult) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 비동기 피킹 작업을 완료합니다.
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 완료할 비동기 피킹 작업과 최종 결과를 검색할 비동기 피킹 작업을 식별하는 항목입니다.
반품
Message 완료된 비동기 작업과 연결된 작업입니다.
예외
매개 변수는 asyncResult .입니다 null.
매개 변수의 구문이 asyncResult 잘못되었습니다.
메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.
예제
다음 코드 예제에서는 이름이 이벤트 MyPeekCompleted처리기를 만들고, 이벤트 처리기 대리자에게 연결 PeekCompleted 하고, 경로 ".\myQueue"에 있는 큐에서 비동기 피킹 작업을 시작하도록 호출 BeginPeek 합니다.
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 시킨 메시지를 읽는 데 사용됩니다.
메시지를 비동기적으로 피킹하려면 호출BeginPeek한 후 다시 호출 EndPeek(IAsyncResult) 할 수 있습니다.
다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.
| 작업 그룹 모드 | 이용 가능 |
|---|---|
| 로컬 컴퓨터 | Yes |
| 로컬 컴퓨터 및 직접 형식 이름 | Yes |
| 원격 컴퓨터 | No |
| 원격 컴퓨터 및 직접 형식 이름 | Yes |