MessageQueue.EndReceive(IAsyncResult) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 비동기 수신 작업을 완료합니다.
public:
System::Messaging::Message ^ EndReceive(IAsyncResult ^ asyncResult);
public System.Messaging.Message EndReceive(IAsyncResult asyncResult);
member this.EndReceive : IAsyncResult -> System.Messaging.Message
Public Function EndReceive (asyncResult As IAsyncResult) As Message
매개 변수
- asyncResult
- IAsyncResult
IAsyncResult 완료할 비동기 수신 작업과 최종 결과를 검색할 비동기 수신 작업을 식별하는 항목입니다.
반품
Message 완료된 비동기 작업과 연결된 작업입니다.
예외
매개 변수는 asyncResult .입니다 null.
매개 변수의 구문이 asyncResult 잘못되었습니다.
메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.
예제
다음 코드 예제에서는 비동기 요청을 연결합니다. 로컬 컴퓨터에 "myQueue"라는 큐가 있다고 가정합니다. 함수는 Main 루틴에서 처리하는 MyReceiveCompleted 비동기 작업을 시작합니다.
MyReceiveCompleted 는 현재 메시지를 처리하고 새 비동기 수신 작업을 시작합니다.
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
using namespace System::Threading;
ref class MyNewQueue
{
public:
// Define static class members.
static ManualResetEvent^ signal = gcnew ManualResetEvent( false );
static int count = 0;
// Provides an event handler for the ReceiveCompleted
// event.
static void MyReceiveCompleted( Object^ source, ReceiveCompletedEventArgs^ asyncResult )
{
try
{
// Connect to the queue.
MessageQueue^ mq = dynamic_cast<MessageQueue^>(source);
// End the asynchronous receive operation.
mq->EndReceive( asyncResult->AsyncResult );
count += 1;
if ( count == 10 )
{
signal->Set();
}
// Restart the asynchronous receive operation.
mq->BeginReceive();
}
catch ( MessageQueueException^ )
{
// Handle sources of MessageQueueException.
}
// Handle other exceptions.
return;
}
};
// Provides an entry point into the application.
//
// This example performs asynchronous receive
// 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 ReceiveCompleted event.
myQueue->ReceiveCompleted += gcnew ReceiveCompletedEventHandler( MyNewQueue::MyReceiveCompleted );
// Begin the asynchronous receive operation.
myQueue->BeginReceive();
MyNewQueue::signal->WaitOne();
// Do other work on the current thread.
return 0;
}
using System;
using System.Messaging;
using System.Threading;
namespace MyProject
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
// Define static class members.
static ManualResetEvent signal = new ManualResetEvent(false);
static int count = 0;
//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous receive
// 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 ReceiveCompleted event.
myQueue.ReceiveCompleted +=
new ReceiveCompletedEventHandler(MyReceiveCompleted);
// Begin the asynchronous receive operation.
myQueue.BeginReceive();
signal.WaitOne();
// Do other work on the current thread.
return;
}
//***************************************************
// Provides an event handler for the ReceiveCompleted
// event.
//***************************************************
private static void MyReceiveCompleted(Object source,
ReceiveCompletedEventArgs asyncResult)
{
try
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;
// End the asynchronous receive operation.
Message m = mq.EndReceive(asyncResult.AsyncResult);
count += 1;
if (count == 10)
{
signal.Set();
}
// Restart the asynchronous receive operation.
mq.BeginReceive();
}
catch(MessageQueueException)
{
// Handle sources of MessageQueueException.
}
// Handle other exceptions.
return;
}
}
}
Imports System.Messaging
Imports System.Threading
' Provides a container class for the example.
Public Class MyNewQueue
' Define static class members.
Private Shared signal As New ManualResetEvent(False)
Private Shared count As Integer = 0
' Provides an entry point into the application.
'
' This example performs asynchronous receive
' 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 ReceiveCompleted event.
AddHandler myQueue.ReceiveCompleted, AddressOf _
MyReceiveCompleted
' Begin the asynchronous receive operation.
myQueue.BeginReceive()
signal.WaitOne()
' Do other work on the current thread.
Return
End Sub
' Provides an event handler for the ReceiveCompleted
' event.
Private Shared Sub MyReceiveCompleted(ByVal [source] As _
[Object], ByVal asyncResult As ReceiveCompletedEventArgs)
Try
' Connect to the queue.
Dim mq As MessageQueue = CType([source], MessageQueue)
' End the asynchronous receive operation.
Dim m As Message = _
mq.EndReceive(asyncResult.AsyncResult)
count += 1
If count = 10 Then
signal.Set()
End If
' Restart the asynchronous receive operation.
mq.BeginReceive()
Catch
' Handle sources of MessageQueueException.
' Handle other exceptions.
End Try
Return
End Sub
End Class
설명
ReceiveCompleted 이벤트가 발생하면 EndReceive(IAsyncResult) 호출에 의해 시작된 작업을 완료합니다BeginReceive. 이렇게 EndReceive(IAsyncResult) 하려면 메시지를 받습니다.
BeginReceive 는 시간 초과를 지정할 수 있으며, 이로 인해 ReceiveCompleted 큐에 메시지가 표시되기 전에 시간 초과가 발생할 경우 이벤트가 발생합니다. 큐에 메시지가 도착하지 않고 시간 초과가 발생하면 후속 호출에서 예외를 EndReceive(IAsyncResult) throw합니다.
EndReceive(IAsyncResult) 는 이벤트를 발생 ReceiveCompleted 시킨 메시지를 읽어(큐에서 제거)하는 데 사용됩니다.
메시지를 비동기적으로 계속 받으려면 호출EndReceive(IAsyncResult)한 후 다시 호출 BeginReceive 할 수 있습니다.
다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.
| 작업 그룹 모드 | 이용 가능 |
|---|---|
| 로컬 컴퓨터 | Yes |
| 로컬 컴퓨터 및 직접 형식 이름 | Yes |
| 원격 컴퓨터 | No |
| 원격 컴퓨터 및 직접 형식 이름 | Yes |