MessageQueue.EndPeek(IAsyncResult) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menyelesaikan operasi intip asinkron yang ditentukan.
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
Parameter
- asyncResult
- IAsyncResult
IAsyncResult yang mengidentifikasi operasi intip asinkron untuk menyelesaikan dan dari mana mengambil hasil akhir.
Mengembalikan
yang Message terkait dengan operasi asinkron yang telah selesai.
Pengecualian
Parameternya asyncResult
adalah null
.
Sintaks asyncResult
parameter tidak valid.
Terjadi kesalahan saat mengakses metode Antrean Pesan.
Contoh
Contoh kode berikut membuat penanganan aktivitas bernama MyPeekCompleted
, melampirkannya ke PeekCompleted delegasi penanganan aktivitas, dan memanggil BeginPeek untuk memulai operasi intip asinkron pada antrean yang terletak di jalur ".\myQueue". PeekCompleted Saat peristiwa dinaikkan, contoh mengintip pesan dan menulis isinya ke layar. Contoh kemudian memanggil BeginPeek lagi untuk memulai operasi intip asinkron baru.
#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
Keterangan
PeekCompleted Ketika peristiwa dinaikkan, EndPeek(IAsyncResult) selesaikan operasi yang dimulai oleh BeginPeek panggilan. Untuk melakukannya, EndPeek(IAsyncResult) mengintip pesan.
BeginPeek dapat menentukan waktu habis, yang menyebabkan PeekCompleted peristiwa dinaikkan jika waktu habis terjadi sebelum pesan muncul dalam antrean. Ketika waktu habis terjadi tanpa pesan yang tiba dalam antrean, panggilan berikutnya untuk EndPeek(IAsyncResult) melemparkan pengecualian.
EndPeek(IAsyncResult) digunakan untuk membaca pesan yang menyebabkan PeekCompleted peristiwa dinaikkan.
Jika Anda ingin terus mengintip pesan secara asinkron, Anda dapat kembali memanggil BeginPeek setelah memanggil EndPeek(IAsyncResult).
Tabel berikut ini memperlihatkan apakah metode ini tersedia dalam berbagai mode Grup Kerja.
Mode grup kerja | Tersedia |
---|---|
Komputer lokal | Ya |
Komputer lokal dan nama format langsung | Ya |
Komputer jarak jauh | Tidak |
Komputer jarak jauh dan nama format langsung | Ya |