MessageQueue.EndReceive(IAsyncResult) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Befejezi a megadott aszinkron fogadási műveletet.
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
Paraméterek
- asyncResult
- IAsyncResult
Az IAsyncResult aszinkron fogadási műveletet azonosítja, amely befejeződik, és amelyből lekéri a végeredményt.
Válaszok
A Message befejezett aszinkron művelethez társított.
Kivételek
A asyncResult paraméter a következő null: .
A paraméter szintaxisa asyncResult érvénytelen.
Hiba történt a Message Queuing metódus elérésekor.
Példák
Az alábbi példakód az aszinkron kéréseket láncra fonja. Feltételezi, hogy a helyi számítógépen van egy "myQueue" nevű üzenetsor. A Main függvény elindítja a rutin által MyReceiveCompleted kezelt aszinkron műveletet.
MyReceiveCompleted feldolgozza az aktuális üzenetet, és elindít egy új aszinkron fogadási műveletet.
#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
Megjegyzések
Az ReceiveCompleted esemény indításakor EndReceive(IAsyncResult) befejezi a hívás által BeginReceive kezdeményezett műveletet. EndReceive(IAsyncResult) Ehhez megkapja az üzenetet.
BeginReceive megadhatja az időtúllépést, ami miatt az ReceiveCompleted esemény akkor lép fel, ha az időtúllépés azelőtt történik, hogy egy üzenet megjelenik az üzenetsorban. Ha időtúllépés történik anélkül, hogy üzenet érkezik az üzenetsorba, egy későbbi hívás EndReceive(IAsyncResult) kivételt eredményez.
EndReceive(IAsyncResult) az eseményt kiváltó ReceiveCompleted üzenet olvasására (az üzenetsorból való eltávolítására) szolgál.
Ha továbbra is aszinkron módon szeretné fogadni az üzeneteket, hívás után EndReceive(IAsyncResult)ismét hívhatBeginReceive.
Az alábbi táblázat azt mutatja be, hogy ez a módszer elérhető-e különböző munkacsoport-módban.
| Munkacsoport mód | Elérhető |
|---|---|
| Helyi számítógép | Igen |
| Helyi számítógép és közvetlen formátum neve | Igen |
| Távoli számítógép | No |
| Távoli számítógép és közvetlen formátum neve | Igen |