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 アタッチし、 を呼び出 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
注釈
イベントが PeekCompleted 発生すると、 EndPeek(IAsyncResult) 呼び出しによって開始された操作が BeginPeek 完了します。 これを行うには、 EndPeek(IAsyncResult) メッセージをピークします。
BeginPeek はタイムアウトを指定できます。これにより、メッセージが PeekCompleted キューに表示される前にタイムアウトが発生した場合にイベントが発生します。 キューにメッセージが到着せずにタイムアウトが発生すると、後続の を EndPeek(IAsyncResult) 呼び出すと例外がスローされます。
EndPeek(IAsyncResult) は、イベントが発生する原因となったメッセージを PeekCompleted 読み取るために使用されます。
メッセージを非同期的にピークし続ける場合は、 を呼び出した後にもう一度 を呼び出BeginPeekEndPeek(IAsyncResult)すことができます。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
ワークグループ モード | 利用可能 |
---|---|
ローカル コンピューター | はい |
ローカル コンピューターと直接の形式名 | はい |
リモート コンピューター | いいえ |
リモート コンピューターと直接形式の名前 | はい |
適用対象
こちらもご覧ください
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示