MessageQueue.PeekCompleted イベント
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
キューから削除されずにメッセージが読み取られるときに発生します。 これは、非同期操作 ( BeginPeek()) の結果です。
public:
event System::Messaging::PeekCompletedEventHandler ^ PeekCompleted;
[System.Messaging.MessagingDescription("MQ_PeekCompleted")]
public event System.Messaging.PeekCompletedEventHandler PeekCompleted;
[<System.Messaging.MessagingDescription("MQ_PeekCompleted")>]
member this.PeekCompleted : System.Messaging.PeekCompletedEventHandler
Public Custom Event PeekCompleted As PeekCompletedEventHandler
イベントの種類
- 属性
例
次のコード例では、 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 イベントを発生させるために非同期処理で使用されます。
EndPeek(IAsyncResult) は、 BeginPeek の呼び出しによって開始された操作を完了し、 PeekCompleted イベントが発生したときにメッセージをピークするために使用されます。
PeekCompletedEventHandler デリゲートを作成するときは、イベントを処理するメソッドを識別します。 イベントをイベント ハンドラーに関連付けるには、デリゲートのインスタンスをイベントに追加します。 デリゲートを削除しない限り、イベントが発生するたびにイベント ハンドラーが呼び出されます。 イベント ハンドラー デリゲートの詳細については、「イベントの 処理と発生」を参照してください。