ReceiveCompletedEventArgs ReceiveCompletedEventArgs ReceiveCompletedEventArgs ReceiveCompletedEventArgs Class

定義

ReceiveCompleted イベントのデータを提供します。Provides data for the ReceiveCompleted event. 非同期の受信操作がイベント ハンドラーを呼び出すと、このクラスのインスタンスがハンドラーに渡されます。When your asynchronous receive operation calls an event handler, an instance of this class is passed to the handler.

public ref class ReceiveCompletedEventArgs : EventArgs
public class ReceiveCompletedEventArgs : EventArgs
type ReceiveCompletedEventArgs = class
    inherit EventArgs
Public Class ReceiveCompletedEventArgs
Inherits EventArgs
継承
ReceiveCompletedEventArgsReceiveCompletedEventArgsReceiveCompletedEventArgsReceiveCompletedEventArgs

次のコード例のイベント ハンドラーを作成する、ReceiveCompletedイベントとイベントでの委任を使用して、ReceiveCompletedEventHandlerします。The following code example creates an event handler for the ReceiveCompleted event and associates it with the event delegate by using the ReceiveCompletedEventHandler. イベント ハンドラー、 MyReceiveCompleted、キューからメッセージを受信および画面に、本文を書き込みます。The event handler, MyReceiveCompleted, receives a message from a queue and writes its body to the screen.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   //*************************************************
   // Provides an event handler for the ReceiveCompleted
   // event.
   //*************************************************
   static void MyReceiveCompleted( Object^ source, ReceiveCompletedEventArgs^ asyncResult )
   {
      // Connect to the queue.
      MessageQueue^ mq = dynamic_cast<MessageQueue^>(source);

      // End the asynchronous Receive operation.
      Message^ m = mq->EndReceive( asyncResult->AsyncResult );

      // Display message information on the screen.
      Console::WriteLine( "Message: {0}", m->Body );

      // Restart the asynchronous Receive operation.
      mq->BeginReceive();
      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();

   // 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 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();
			
			// Do other work on the current thread.

			return;
		}


		//**************************************************
		// Provides an event handler for the ReceiveCompleted
		// event.
		//**************************************************
		
		private static void MyReceiveCompleted(Object source, 
			ReceiveCompletedEventArgs asyncResult)
		{
			// Connect to the queue.
			MessageQueue mq = (MessageQueue)source;

			// End the asynchronous Receive operation.
			Message m = mq.EndReceive(asyncResult.AsyncResult);

			// Display message information on the screen.
			Console.WriteLine("Message: " + (string)m.Body);

			// Restart the asynchronous Receive operation.
			mq.BeginReceive();
			
			return; 
		}
	}
}
Imports System
Imports System.Messaging

Public Class MyNewQueue


        '
        ' 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()

            ' Do other work on the current thread.

            Return

        End Sub 'Main


        '
        ' Provides an event handler for the ReceiveCompleted
        ' event.
        '

        Private Shared Sub MyReceiveCompleted(ByVal [source] As _
            [Object], ByVal asyncResult As ReceiveCompletedEventArgs)

            ' Connect to the queue.
            Dim mq As MessageQueue = CType([source], MessageQueue)

            ' End the asynchronous Receive operation.
            Dim m As Message = mq.EndReceive(asyncResult.AsyncResult)

            ' Display message information on the screen.
            Console.WriteLine(("Message: " + CStr(m.Body)))

            ' Restart the asynchronous Receive operation.
            mq.BeginReceive()

            Return

        End Sub 'MyReceiveCompleted

End Class 'MyNewQueue

注釈

イベント通知を使用して、キューから非同期的にメッセージを受信するときにメッセージを処理するメソッドを作成する必要があります。When you use event notification to receive messages asynchronously from the queue, you must create a method that handles your message processing. コードを呼び出す必要がありますBeginReceive非同期処理を開始します。Your code must call BeginReceive to begin the asynchronous processing. アプリケーションに通知メッセージが受信したときに、ReceiveCompletedイベント。When a message is received, your application is notified through the ReceiveCompleted event. インスタンスReceiveCompletedEventArgsイベント デリゲートを呼び出すイベント ハンドラーに渡されます。An instance of ReceiveCompletedEventArgs is passed into the event delegate that calls your event handler. 関連付けられているデータ、ReceiveCompletedデリゲートにイベントが含まれているAsyncResultパラメーター。The data associated with the ReceiveCompleted event is contained in the delegate's AsyncResult parameter.

イベントの完了通知を提供する 2 つの方法: イベント通知とコールバック。There are two ways to provide notification of event completion: event notification and callbacks. ReceiveCompletedEventArgs イベント通知でのみ使用されます。ReceiveCompletedEventArgs is used only with event notification. コールバックとイベント通知の比較については、"イベントとを参照してください。MSDN で"コールバック。For information comparing callbacks and event notification, see "Events vs. Callbacks" on MSDN.

ReceiveCompletedEventArgs アクセスを提供します。 非同期の終了を開始したメッセージの受信操作を通じて、Messageメンバー。ReceiveCompletedEventArgs provides access to the message that initiated the end of the asynchronous receive operation, through the Message member. これは、メッセージへの代替であり、動作への呼び出しとほぼ同じMessageQueue.EndReceiveします。This is an alternate access to the message, and behaves much the same as a call to MessageQueue.EndReceive.

プロパティ

AsyncResult AsyncResult AsyncResult AsyncResult

要求された非同期操作の結果を取得または設定します。Gets or sets the result of the asynchronous operation requested.

Message Message Message Message

非同期の受信操作に関連付けられているメッセージを取得します。Gets the message associated with the asynchronous receive operation.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください