MessageQueue.Receive メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
キュー内の最初のメッセージを受信し、キューからメッセージを削除します。
オーバーロード
| 名前 | 説明 |
|---|---|
| Receive() |
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、メッセージが使用可能になるまで現在の実行スレッドをブロックします。 |
| Receive(MessageQueueTransaction) |
MessageQueueによって参照されるトランザクション キューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、メッセージが使用可能になるまで現在の実行スレッドをブロックします。 |
| Receive(MessageQueueTransactionType) |
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、メッセージが使用可能になるまで現在の実行スレッドをブロックします。 |
| Receive(TimeSpan) |
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信し、キューでメッセージが使用可能になるか、タイムアウトが切れるまで待機します。 |
| Receive(TimeSpan, Cursor) |
指定したカーソルを使用して、キュー内の現在のメッセージを受信します。 使用できるメッセージがない場合、このメソッドはメッセージが使用可能になるか、タイムアウトが切れるまで待機します。 |
| Receive(TimeSpan, MessageQueueTransaction) |
MessageQueueによって参照されるトランザクション キューで使用可能な最初のメッセージを受信し、キューでメッセージが使用可能になるか、タイムアウトが切れるまで待機します。 |
| Receive(TimeSpan, MessageQueueTransactionType) |
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、キューでメッセージが使用可能になるか、タイムアウトが切れるまで待機します。 |
| Receive(TimeSpan, Cursor, MessageQueueTransaction) |
指定したカーソルを使用して、キュー内の現在のメッセージを受信します。 使用できるメッセージがない場合、このメソッドはメッセージが使用可能になるか、タイムアウトが切れるまで待機します。 |
| Receive(TimeSpan, Cursor, MessageQueueTransactionType) |
指定したカーソルを使用して、キュー内の現在のメッセージを受信します。 使用できるメッセージがない場合、このメソッドはメッセージが使用可能になるか、タイムアウトが切れるまで待機します。 |
Receive()
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、メッセージが使用可能になるまで現在の実行スレッドをブロックします。
public:
System::Messaging::Message ^ Receive();
public System.Messaging.Message Receive();
member this.Receive : unit -> System.Messaging.Message
Public Function Receive () As Message
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
メッセージ キュー メソッドにアクセスするときにエラーが発生しました。
例
次のコード例では、キューからメッセージを受信し、そのメッセージに関する情報を画面に出力します。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
// This class represents an object the following example
// sends to a queue and receives from a queue.
ref class Order
{
public:
int orderId;
DateTime orderTime;
};
/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:
//*************************************************
// Sends an Order to a queue.
//*************************************************
void SendMessage()
{
// Create a new order and set values.
Order^ sentOrder = gcnew Order;
sentOrder->orderId = 3;
sentOrder->orderTime = DateTime::Now;
// Connect to a queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
// Send the Order to the queue.
myQueue->Send( sentOrder );
return;
}
//*************************************************
// Receives a message containing an Order.
//*************************************************
void ReceiveMessage()
{
// Connect to the a queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
// Set the formatter to indicate body contains an Order.
array<Type^>^p = gcnew array<Type^>(1);
p[ 0 ] = Order::typeid;
myQueue->Formatter = gcnew XmlMessageFormatter( p );
try
{
// Receive and format the message.
Message^ myMessage = myQueue->Receive();
Order^ myOrder = static_cast<Order^>(myMessage->Body);
// Display message information.
Console::WriteLine( "Order ID: {0}", myOrder->orderId );
Console::WriteLine( "Sent: {0}", myOrder->orderTime );
}
catch ( MessageQueueException^ )
{
// Handle Message Queuing exceptions.
}
// Handle invalid serialization format.
catch ( InvalidOperationException^ e )
{
Console::WriteLine( e->Message );
}
// Catch other exceptions as necessary.
return;
}
};
//*************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a queue.
//*************************************************
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Send a message to a queue.
myNewQueue->SendMessage();
// Receive a message from a queue.
myNewQueue->ReceiveMessage();
return 0;
}
using System;
using System.Messaging;
namespace MyProject
{
// This class represents an object the following example
// sends to a queue and receives from a queue.
public class Order
{
public int orderId;
public DateTime orderTime;
};
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a queue.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Send a message to a queue.
myNewQueue.SendMessage();
// Receive a message from a queue.
myNewQueue.ReceiveMessage();
return;
}
//**************************************************
// Sends an Order to a queue.
//**************************************************
public void SendMessage()
{
// Create a new order and set values.
Order sentOrder = new Order();
sentOrder.orderId = 3;
sentOrder.orderTime = DateTime.Now;
// Connect to a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Send the Order to the queue.
myQueue.Send(sentOrder);
return;
}
//**************************************************
// Receives a message containing an Order.
//**************************************************
public void ReceiveMessage()
{
// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Set the formatter to indicate body contains an Order.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(MyProject.Order)});
try
{
// Receive and format the message.
Message myMessage = myQueue.Receive();
Order myOrder = (Order)myMessage.Body;
// Display message information.
Console.WriteLine("Order ID: " +
myOrder.orderId.ToString());
Console.WriteLine("Sent: " +
myOrder.orderTime.ToString());
}
catch (MessageQueueException)
{
// Handle Message Queuing exceptions.
}
// Handle invalid serialization format.
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}
// Catch other exceptions as necessary.
return;
}
}
}
Imports System.Messaging
' This class represents an object the following example
' sends to a queue and receives from a queue.
Public Class Order
Public orderId As Integer
Public orderTime As DateTime
End Class
Public Class MyNewQueue
'
' Provides an entry point into the application.
'
' This example sends and receives a message from
' a qeue.
'
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue()
' Send a message to a queue.
myNewQueue.SendMessage()
' Receive a message from a queue.
myNewQueue.ReceiveMessage()
Return
End Sub
'
' Sends an Order to a queue.
'
Public Sub SendMessage()
' Create a new order and set values.
Dim sentOrder As New Order()
sentOrder.orderId = 3
sentOrder.orderTime = DateTime.Now
' Connect to a queue on the local computer.
Dim myQueue As New MessageQueue(".\myQueue")
' Send the Order to the queue.
myQueue.Send(sentOrder)
Return
End Sub
'
' Receives a message containing an Order.
'
Public Sub ReceiveMessage()
' Connect to the a queue on the local computer.
Dim myQueue As New MessageQueue(".\myQueue")
' Set the formatter to indicate the body contains an Order.
myQueue.Formatter = New XmlMessageFormatter(New Type() _
{GetType(Order)})
Try
' Receive and format the message.
Dim myMessage As Message = myQueue.Receive()
Dim myOrder As Order = CType(myMessage.Body, Order)
' Display message information.
Console.WriteLine(("Order ID: " + _
myOrder.orderId.ToString()))
Console.WriteLine(("Sent: " + _
myOrder.orderTime.ToString()))
Catch m As MessageQueueException
' Handle Message Queuing exceptions.
Catch e As InvalidOperationException
' Handle invalid serialization format.
Console.WriteLine(e.Message)
' Catch other exceptions as necessary.
End Try
Return
End Sub
End Class
注釈
このオーバーロードを使用してキューからメッセージを受信するか、キューにメッセージが入るまで待機します。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キュー内の後続のメッセージ、または新しい優先度の高いメッセージが返されます。
キューから削除せずにキュー内の最初のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peek メソッドは常にキュー内の最初のメッセージを返します。そのため、後続のメソッドの呼び出しでは、優先順位の高いメッセージがキューに到着しない限り、同じメッセージが返されます。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 Receive メソッドのこのオーバーロードは無限タイムアウトを指定するため、アプリケーションは無期限に待機する可能性があります。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(MessageQueueTransaction)
MessageQueueによって参照されるトランザクション キューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、メッセージが使用可能になるまで現在の実行スレッドをブロックします。
public:
System::Messaging::Message ^ Receive(System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message Receive(System.Messaging.MessageQueueTransaction transaction);
member this.Receive : System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function Receive (transaction As MessageQueueTransaction) As Message
パラメーター
- transaction
- MessageQueueTransaction
MessageQueueTransaction オブジェクトです。
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
例
次のコード例では、ローカル コンピューター上のトランザクション キューに接続し、キューにメッセージを送信します。 その後、注文を含むメッセージを受信します。 非トランザクション キューが発生した場合は、トランザクションがスローされ、例外が発生し、トランザクションがロールバックされます。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:
//*************************************************
// Sends a message to a queue.
//*************************************************
void SendMessageTransactional()
{
// Connect to a queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );
// Send a message to the queue.
if ( myQueue->Transactional )
{
// Create a transaction.
MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
// Begin the transaction.
myTransaction->Begin();
// Send the message.
myQueue->Send( "My Message Data.", myTransaction );
// Commit the transaction.
myTransaction->Commit();
}
return;
}
//*************************************************
// Receives a message containing an Order.
//*************************************************
void ReceiveMessageTransactional()
{
// Connect to a transactional queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );
// Set the formatter.
array<Type^>^p = gcnew array<Type^>(1);
p[ 0 ] = String::typeid;
myQueue->Formatter = gcnew XmlMessageFormatter( p );
// Create a transaction.
MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
try
{
// Begin the transaction.
myTransaction->Begin();
// Receive the message.
Message^ myMessage = myQueue->Receive( myTransaction );
String^ myOrder = static_cast<String^>(myMessage->Body);
// Display message information.
Console::WriteLine( myOrder );
// Commit the transaction.
myTransaction->Commit();
}
catch ( MessageQueueException^ e )
{
// Handle nontransactional queues.
if ( e->MessageQueueErrorCode == MessageQueueErrorCode::TransactionUsage )
{
Console::WriteLine( "Queue is not transactional." );
}
// Else catch other sources of a MessageQueueException.
// Roll back the transaction.
myTransaction->Abort();
}
// Catch other exceptions as necessary, such as
// InvalidOperationException, thrown when the formatter
// cannot deserialize the message.
return;
}
};
//*************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a transactional queue.
//*************************************************
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Send a message to a queue.
myNewQueue->SendMessageTransactional();
// Receive a message from a queue.
myNewQueue->ReceiveMessageTransactional();
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 sends and receives a message from
// a transactional queue.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Send a message to a queue.
myNewQueue.SendMessageTransactional();
// Receive a message from a queue.
myNewQueue.ReceiveMessageTransactional();
return;
}
//**************************************************
// Sends a message to a queue.
//**************************************************
public void SendMessageTransactional()
{
// Connect to a queue on the local computer.
MessageQueue myQueue = new
MessageQueue(".\\myTransactionalQueue");
// Send a message to the queue.
if (myQueue.Transactional)
{
// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
// Begin the transaction.
myTransaction.Begin();
// Send the message.
myQueue.Send("My Message Data.", myTransaction);
// Commit the transaction.
myTransaction.Commit();
}
return;
}
//**************************************************
// Receives a message containing an Order.
//**************************************************
public void ReceiveMessageTransactional()
{
// Connect to a transactional queue on the local computer.
MessageQueue myQueue = new
MessageQueue(".\\myTransactionalQueue");
// Set the formatter.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
try
{
// Begin the transaction.
myTransaction.Begin();
// Receive the message.
Message myMessage = myQueue.Receive(myTransaction);
String myOrder = (String)myMessage.Body;
// Display message information.
Console.WriteLine(myOrder);
// Commit the transaction.
myTransaction.Commit();
}
catch (MessageQueueException e)
{
// Handle nontransactional queues.
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.TransactionUsage)
{
Console.WriteLine("Queue is not transactional.");
}
// Else catch other sources of a MessageQueueException.
// Roll back the transaction.
myTransaction.Abort();
}
// Catch other exceptions as necessary, such as
// InvalidOperationException, thrown when the formatter
// cannot deserialize the message.
return;
}
}
}
Imports System.Messaging
Public Class MyNewQueue
'
' Provides an entry point into the application.
'
' This example sends and receives a message from
' a transactional queue.
'
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue
' Send a message to a queue.
myNewQueue.SendMessageTransactional()
' Receive a message from a queue.
myNewQueue.ReceiveMessageTransactional()
Return
End Sub
'
' Sends a message to a queue.
'
Public Sub SendMessageTransactional()
' Connect to a queue on the local computer.
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
' Send a message to the queue.
If myQueue.Transactional = True Then
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
' Begin the transaction.
myTransaction.Begin()
' Send the message.
myQueue.Send("My Message Data.", myTransaction)
' Commit the transaction.
myTransaction.Commit()
End If
Return
End Sub
'
' Receives a message containing an Order.
'
Public Sub ReceiveMessageTransactional()
' Connect to a transactional queue on the local computer.
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
' Set the formatter.
myQueue.Formatter = New XmlMessageFormatter(New Type() _
{GetType([String])})
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
Try
' Begin the transaction.
myTransaction.Begin()
' Receive the message.
Dim myMessage As Message = _
myQueue.Receive(myTransaction)
Dim myOrder As [String] = CType(myMessage.Body, _
[String])
' Display message information.
Console.WriteLine(myOrder)
' Commit the transaction.
myTransaction.Commit()
Catch e As MessageQueueException
' Handle nontransactional queues.
If e.MessageQueueErrorCode = _
MessageQueueErrorCode.TransactionUsage Then
Console.WriteLine("Queue is not transactional.")
End If
' Else catch other sources of a MessageQueueException.
' Roll back the transaction.
myTransaction.Abort()
' Catch other exceptions as necessary, such as
' InvalidOperationException, thrown when the formatter
' cannot deserialize the message.
End Try
Return
End Sub
End Class
注釈
このオーバーロードを使用して、 transaction パラメーターで定義された内部トランザクション コンテキストを使用してトランザクション キューからメッセージを受信するか、キューにメッセージが存在するまで待機します。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キュー内の後続のメッセージが返されます。
このメソッドはトランザクション キューで呼び出されるため、トランザクションが中止されると、受信したメッセージがキューに返されます。 トランザクションがコミットされるまで、メッセージはキューから完全に削除されません。
キューから削除せずにキュー内の最初のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peek メソッドは常にキュー内の最初のメッセージを返します。そのため、後続のメソッドの呼び出しでは、優先順位の高いメッセージがキューに到着しない限り、同じメッセージが返されます。 Peekの呼び出しによって返されるメッセージに関連付けられたトランザクション コンテキストはありません。 Peekはキュー内のメッセージを削除しないため、Abortの呼び出しによってロールバックするものは何もありません。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 Receive メソッドのこのオーバーロードは無限タイムアウトを指定するため、アプリケーションは無期限に待機する可能性があります。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(MessageQueueTransactionType)
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、メッセージが使用可能になるまで現在の実行スレッドをブロックします。
public:
System::Messaging::Message ^ Receive(System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message Receive(System.Messaging.MessageQueueTransactionType transactionType);
member this.Receive : System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function Receive (transactionType As MessageQueueTransactionType) As Message
パラメーター
- transactionType
- MessageQueueTransactionType
メッセージに関連付けるトランザクション コンテキストの種類を記述する、 MessageQueueTransactionType 値の 1 つ。
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
メッセージ キュー メソッドにアクセスするときにエラーが発生しました。
transactionType パラメーターは、MessageQueueTransactionType メンバーの 1 つではありません。
例
次のコード例は、 Receive(MessageQueueTransactionType)の使用方法を示しています。
// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");
// Create a new message.
Message^ msg = gcnew Message("Example Message Body");
// Send the message.
queue->Send(msg, MessageQueueTransactionType::Single);
// Simulate doing other work so the message has time to arrive.
System::Threading::Thread::Sleep(TimeSpan::FromSeconds(10.0));
// Set the formatter to indicate the message body contains a String.
queue->Formatter = gcnew XmlMessageFormatter(
gcnew array<Type^>{String::typeid});
// Receive the message from the queue. Because the Id of the message
// , it might not be the message just sent.
msg = queue->Receive(MessageQueueTransactionType::Single);
queue->Close();
// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");
// Create a new message.
Message msg = new Message("Example Message Body");
// Send the message.
queue.Send(msg, MessageQueueTransactionType.Single);
// Simulate doing other work so the message has time to arrive.
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10.0));
// Set the formatter to indicate the message body contains a String.
queue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Receive the message from the queue. Because the Id of the message
// , it might not be the message just sent.
msg = queue.Receive(MessageQueueTransactionType.Single);
注釈
このオーバーロードを使用して、 transactionType パラメーターで定義されたトランザクション コンテキストを使用してキューからメッセージを受信するか、キューにメッセージが入るまで待機します。
メッセージの受信に使用するスレッドに外部トランザクション コンテキストが既にアタッチされている場合は、Automatic パラメーターのtransactionTypeを指定します。 メッセージを 1 つの内部トランザクションとして受信する場合は、 Single を指定します。 トランザクション コンテキスト外のトランザクション キューからメッセージを受信する場合は、 None を指定できます。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キュー内の後続のメッセージが返されます。
トランザクション キューからメッセージを受信するためにこのメソッドが呼び出された場合、トランザクションが中止されると、受信したメッセージがキューに返されます。 トランザクションがコミットされるまで、メッセージはキューから完全に削除されません。
キューから削除せずにキュー内の最初のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peek メソッドは常にキュー内の最初のメッセージを返します。そのため、後続のメソッドの呼び出しでは、優先順位の高いメッセージがキューに到着しない限り、同じメッセージが返されます。 Peekの呼び出しによって返されるメッセージに関連付けられたトランザクション コンテキストはありません。 Peekはキュー内のメッセージを削除しないため、Abortの呼び出しによってロールバックするものは何もありません。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 Receive メソッドのこのオーバーロードは無限タイムアウトを指定するため、アプリケーションは無期限に待機する可能性があります。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(TimeSpan)
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信し、キューでメッセージが使用可能になるか、タイムアウトが切れるまで待機します。
public:
System::Messaging::Message ^ Receive(TimeSpan timeout);
public System.Messaging.Message Receive(TimeSpan timeout);
member this.Receive : TimeSpan -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan) As Message
パラメーター
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
timeout パラメーターに指定された値が無効です。timeoutがZero未満であるか、InfiniteTimeoutより大きい可能性があります。
例
次のコード例では、キューからメッセージを受信し、そのメッセージに関する情報を画面に出力します。 この例では、メッセージがキューに到着するのを待っている間、実行を最大 5 秒間一時停止します。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
// This class represents an object the following example
// receives from a queue.
ref class Order
{
public:
int orderId;
DateTime orderTime;
};
/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:
//*************************************************
// Receives a message containing an Order.
//*************************************************
void ReceiveMessage()
{
// Connect to the a queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
// Set the formatter to indicate body contains an Order.
array<Type^>^p = gcnew array<Type^>(1);
p[ 0 ] = Order::typeid;
myQueue->Formatter = gcnew XmlMessageFormatter( p );
try
{
// Receive and format the message.
// Wait 5 seconds for a message to arrive.
Message^ myMessage = myQueue->Receive( TimeSpan(0,0,5) );
Order^ myOrder = static_cast<Order^>(myMessage->Body);
// Display message information.
Console::WriteLine( "Order ID: {0}", myOrder->orderId );
Console::WriteLine( "Sent: {0}", myOrder->orderTime );
}
catch ( MessageQueueException^ e )
{
// Handle no message arriving in the queue.
if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
{
Console::WriteLine( "No message arrived in queue." );
}
// Handle other sources of a MessageQueueException.
}
// Handle invalid serialization format.
catch ( InvalidOperationException^ e )
{
Console::WriteLine( e->Message );
}
// Catch other exceptions as necessary.
return;
}
};
//*************************************************
// Provides an entry point into the application.
//
// This example receives a message from a queue.
//*************************************************
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Receive a message from a queue.
myNewQueue->ReceiveMessage();
return 0;
}
using System;
using System.Messaging;
namespace MyProject
{
// This class represents an object the following example
// receives from a queue.
public class Order
{
public int orderId;
public DateTime orderTime;
};
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example receives a message from a queue.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Receive a message from a queue.
myNewQueue.ReceiveMessage();
return;
}
//**************************************************
// Receives a message containing an Order.
//**************************************************
public void ReceiveMessage()
{
// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Set the formatter to indicate body contains an Order.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(MyProject.Order)});
try
{
// Receive and format the message.
// Wait 5 seconds for a message to arrive.
Message myMessage = myQueue.Receive(new
TimeSpan(0,0,5));
Order myOrder = (Order)myMessage.Body;
// Display message information.
Console.WriteLine("Order ID: " +
myOrder.orderId.ToString());
Console.WriteLine("Sent: " +
myOrder.orderTime.ToString());
}
catch (MessageQueueException e)
{
// Handle no message arriving in the queue.
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.IOTimeout)
{
Console.WriteLine("No message arrived in queue.");
}
// Handle other sources of a MessageQueueException.
}
// Handle invalid serialization format.
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}
// Catch other exceptions as necessary.
return;
}
}
}
Imports System.Messaging
' This class represents an object the following example
' receives from a queue.
Public Class Order
Public orderId As Integer
Public orderTime As DateTime
End Class
Public Class MyNewQueue
'
' Provides an entry point into the application.
'
' This example receives a message from a queue.
'
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue()
' Receive a message from a queue.
myNewQueue.ReceiveMessage()
Return
End Sub
'
' Receives a message containing an Order.
'
Public Sub ReceiveMessage()
' Connect to the a queue on the local computer.
Dim myQueue As New MessageQueue(".\myQueue")
' Set the formatter to indicate body contains an Order.
myQueue.Formatter = New XmlMessageFormatter(New Type() _
{GetType(Order)})
Try
' Receive and format the message.
' Wait 5 seconds for a message to arrive.
Dim myMessage As Message = myQueue.Receive(New _
TimeSpan(0, 0, 5))
Dim myOrder As Order = CType(myMessage.Body, Order)
' Display message information.
Console.WriteLine(("Order ID: " + _
myOrder.orderId.ToString()))
Console.WriteLine(("Sent: " + _
myOrder.orderTime.ToString()))
Catch e As MessageQueueException
' Handle no message arriving in the queue.
If e.MessageQueueErrorCode = _
MessageQueueErrorCode.IOTimeout Then
Console.WriteLine("No message arrived in queue.")
End If
' Handle other sources of a MessageQueueException.
Catch e As InvalidOperationException
' Handle invalid serialization format.
Console.WriteLine(e.Message)
' Catch other exceptions as necessary.
End Try
Return
End Sub
End Class
注釈
このオーバーロードを使用してメッセージを受信し、キューにメッセージがない場合は、指定した期間で返します。
Receive メソッドを使用すると、メッセージをキューから削除して同期読み取りを実行できます。 Receiveの後続の呼び出しでは、キュー内の後続のメッセージ、または新しい優先度の高いメッセージが返されます。
キューから削除せずにキュー内の最初のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peek メソッドは常にキュー内の最初のメッセージを返します。そのため、後続のメソッドの呼び出しでは、優先順位の高いメッセージがキューに到着しない限り、同じメッセージが返されます。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 指定した期間、または timeout パラメーターに値InfiniteTimeoutを指定した場合、スレッドは無期限にブロックされます。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(TimeSpan, Cursor)
指定したカーソルを使用して、キュー内の現在のメッセージを受信します。 使用できるメッセージがない場合、このメソッドはメッセージが使用可能になるか、タイムアウトが切れるまで待機します。
public:
System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::Cursor ^ cursor);
public System.Messaging.Message Receive(TimeSpan timeout, System.Messaging.Cursor cursor);
member this.Receive : TimeSpan * System.Messaging.Cursor -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, cursor As Cursor) As Message
パラメーター
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
timeout パラメーターに指定された値が無効です。timeoutがZero未満であるか、InfiniteTimeoutより大きい可能性があります。
タイムアウトが切れる前に、メッセージがキューに到着しませんでした。
-または-
メッセージ キュー メソッドにアクセスするときにエラーが発生しました
このオーバーロードを使用してメッセージを受信し、キューにメッセージがない場合は、指定した期間で返します。
適用対象
Receive(TimeSpan, MessageQueueTransaction)
MessageQueueによって参照されるトランザクション キューで使用可能な最初のメッセージを受信し、キューでメッセージが使用可能になるか、タイムアウトが切れるまで待機します。
public:
System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message Receive(TimeSpan timeout, System.Messaging.MessageQueueTransaction transaction);
member this.Receive : TimeSpan * System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, transaction As MessageQueueTransaction) As Message
パラメーター
- transaction
- MessageQueueTransaction
MessageQueueTransaction オブジェクトです。
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
timeout パラメーターに指定された値が無効です。timeoutがZero未満であるか、InfiniteTimeoutより大きい可能性があります。
タイムアウトが切れる前に、メッセージがキューに到着しませんでした。
-または-
キューは非トランザクションです。
-または-
メッセージ キュー メソッドにアクセスするときにエラーが発生しました。
例
次のコード例は、このメソッドの使用方法を示しています。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:
//*************************************************
// Sends a message to a transactional queue.
//*************************************************
void SendMessageTransactional()
{
// Connect to a queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );
// Send a message to the queue.
if ( myQueue->Transactional)
{
// Create a transaction.
MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
// Begin the transaction.
myTransaction->Begin();
// Send the message.
myQueue->Send( "My Message Data.", myTransaction );
// Commit the transaction.
myTransaction->Commit();
}
return;
}
//*************************************************
// Receives a message from the transactional queue.
//*************************************************
void ReceiveMessageTransactional()
{
// Connect to a transactional queue on the local computer.
MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );
// Set the formatter.
array<Type^>^p = gcnew array<Type^>(1);
p[ 0 ] = String::typeid;
myQueue->Formatter = gcnew XmlMessageFormatter( p );
// Create a transaction.
MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
try
{
// Begin the transaction.
myTransaction->Begin();
// Receive the message.
// Wait five seconds for a message to arrive.
Message^ myMessage = myQueue->Receive( TimeSpan(0,0,5), myTransaction );
String^ myOrder = static_cast<String^>(myMessage->Body);
// Display message information.
Console::WriteLine( myOrder );
// Commit the transaction.
myTransaction->Commit();
}
catch ( MessageQueueException^ e )
{
// Handle nontransactional queues.
if ( e->MessageQueueErrorCode == MessageQueueErrorCode::TransactionUsage )
{
Console::WriteLine( "Queue is not transactional." );
}
// Handle no message arriving in the queue.
else
// Handle no message arriving in the queue.
if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
{
Console::WriteLine( "No message in queue." );
}
// Else catch other sources of MessageQueueException.
// Roll back the transaction.
myTransaction->Abort();
}
// Catch other exceptions as necessary, such as
// InvalidOperationException, thrown when the formatter
// cannot deserialize the message.
return;
}
};
//*************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a transactional queue.
//*************************************************
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Send a message to a queue.
myNewQueue->SendMessageTransactional();
// Receive a message from a queue.
myNewQueue->ReceiveMessageTransactional();
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 sends and receives a message from
// a transactional queue.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Send a message to a queue.
myNewQueue.SendMessageTransactional();
// Receive a message from a queue.
myNewQueue.ReceiveMessageTransactional();
return;
}
//**************************************************
// Sends a message to a transactional queue.
//**************************************************
public void SendMessageTransactional()
{
// Connect to a queue on the local computer.
MessageQueue myQueue = new
MessageQueue(".\\myTransactionalQueue");
// Send a message to the queue.
if (myQueue.Transactional)
{
// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
// Begin the transaction.
myTransaction.Begin();
// Send the message.
myQueue.Send("My Message Data.", myTransaction);
// Commit the transaction.
myTransaction.Commit();
}
return;
}
//**************************************************
// Receives a message from the transactional queue.
//**************************************************
public void ReceiveMessageTransactional()
{
// Connect to a transactional queue on the local computer.
MessageQueue myQueue = new
MessageQueue(".\\myTransactionalQueue");
// Set the formatter.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
try
{
// Begin the transaction.
myTransaction.Begin();
// Receive the message.
// Wait five seconds for a message to arrive.
Message myMessage = myQueue.Receive(new
TimeSpan(0,0,5), myTransaction);
String myOrder = (String)myMessage.Body;
// Display message information.
Console.WriteLine(myOrder);
// Commit the transaction.
myTransaction.Commit();
}
catch (MessageQueueException e)
{
// Handle nontransactional queues.
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.TransactionUsage)
{
Console.WriteLine("Queue is not transactional.");
}
// Handle no message arriving in the queue.
else if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.IOTimeout)
{
Console.WriteLine("No message in queue.");
}
// Else catch other sources of MessageQueueException.
// Roll back the transaction.
myTransaction.Abort();
}
// Catch other exceptions as necessary, such as
// InvalidOperationException, thrown when the formatter
// cannot deserialize the message.
return;
}
}
}
Imports System.Messaging
Namespace MyProj
Public Class MyNewQueue
'**************************************************
' Provides an entry point into the application.
'
' This example sends and receives a message from
' a transactional queue.
'**************************************************
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue
' Send a message to a queue.
myNewQueue.SendMessageTransactional()
' Receive a message from a queue.
myNewQueue.ReceiveMessageTransactional()
Return
End Sub
'**************************************************
' Sends a message to a transactional queue.
'**************************************************
Public Sub SendMessageTransactional()
' Connect to a queue on the local computer.
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
' Send a message to the queue.
If myQueue.Transactional = True Then
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
' Begin the transaction.
myTransaction.Begin()
' Send the message.
myQueue.Send("My Message Data.", myTransaction)
' Commit the transaction.
myTransaction.Commit()
End If
Return
End Sub
'**************************************************
' Receives a message from the transactional queue.
'**************************************************
Public Sub ReceiveMessageTransactional()
' Connect to a transactional queue on the local computer.
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
' Set the formatter.
myQueue.Formatter = New XmlMessageFormatter(New Type() _
{GetType([String])})
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
Try
' Begin the transaction.
myTransaction.Begin()
' Receive the message.
' Wait five seconds for a message to arrive.
Dim myMessage As Message = myQueue.Receive(New _
TimeSpan(0, 0, 5), myTransaction)
Dim myOrder As [String] = CType(myMessage.Body, _
[String])
' Display message information.
Console.WriteLine(myOrder)
' Commit the transaction.
myTransaction.Commit()
Catch e As MessageQueueException
' Handle nontransactional queues.
If e.MessageQueueErrorCode = _
MessageQueueErrorCode.TransactionUsage Then
Console.WriteLine("Queue is not transactional.")
Else
' Handle no message arriving in the queue.
If e.MessageQueueErrorCode = _
MessageQueueErrorCode.IOTimeout Then
Console.WriteLine("No message in queue.")
End If
End If
' Else catch other sources of a MessageQueueException.
' Roll back the transaction.
myTransaction.Abort()
' Catch other exceptions as necessary, such as InvalidOperationException,
' thrown when the formatter cannot deserialize the message.
End Try
Return
End Sub
End Class
End Namespace 'MyProj
注釈
このオーバーロードを使用して、 transaction パラメーターで定義された内部トランザクション コンテキストを使用してトランザクション キューからメッセージを受信し、キューにメッセージがない場合は、指定した期間内に戻ります。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キュー内の後続のメッセージが返されます。
このメソッドはトランザクション キューで呼び出されるため、トランザクションが中止されると、受信したメッセージがキューに返されます。 トランザクションがコミットされるまで、メッセージはキューから完全に削除されません。
キューから削除せずにキュー内の最初のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peek メソッドは常にキュー内の最初のメッセージを返します。そのため、後続のメソッドの呼び出しでは、優先順位の高いメッセージがキューに到着しない限り、同じメッセージが返されます。 Peekの呼び出しによって返されるメッセージに関連付けられたトランザクション コンテキストはありません。 Peekはキュー内のメッセージを削除しないため、Abortの呼び出しによってロールバックするものは何もありません。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 指定した期間、または timeout パラメーターに値InfiniteTimeoutを指定した場合、スレッドは無期限にブロックされます。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(TimeSpan, MessageQueueTransactionType)
MessageQueueによって参照されるキューで使用可能な最初のメッセージを受信します。 この呼び出しは同期的であり、キューでメッセージが使用可能になるか、タイムアウトが切れるまで待機します。
public:
System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message Receive(TimeSpan timeout, System.Messaging.MessageQueueTransactionType transactionType);
member this.Receive : TimeSpan * System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, transactionType As MessageQueueTransactionType) As Message
パラメーター
- transactionType
- MessageQueueTransactionType
メッセージに関連付けるトランザクション コンテキストの種類を記述する、 MessageQueueTransactionType 値の 1 つ。
返品
キューで使用可能な最初のメッセージを参照する Message 。
例外
timeout パラメーターに指定された値が無効です。timeoutがZero未満であるか、InfiniteTimeoutより大きい可能性があります。
transactionType パラメーターは、MessageQueueTransactionType メンバーの 1 つではありません。
例
次のコード例は、このメソッドの使用方法を示しています。
// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");
// Create a new message.
Message^ msg = gcnew Message("Example Message Body");
// Send the message.
queue->Send(msg, MessageQueueTransactionType::Single);
// Set the formatter to indicate the message body contains a String.
queue->Formatter = gcnew XmlMessageFormatter(
gcnew array<Type^>{String::typeid});
// Receive the message from the queue. Because the Id of the message
// is not specified, it might not be the message just sent.
msg = queue->Receive(TimeSpan::FromSeconds(10.0),
MessageQueueTransactionType::Single);
queue->Close();
// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");
// Create a new message.
Message msg = new Message("Example Message Body");
// Send the message.
queue.Send(msg, MessageQueueTransactionType.Single);
// Set the formatter to indicate the message body contains a String.
queue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Receive the message from the queue. Because the Id of the message
// is not specified, it might not be the message just sent.
msg = queue.Receive(TimeSpan.FromSeconds(10.0),
MessageQueueTransactionType.Single);
注釈
このオーバーロードを使用して、 transactionType パラメーターで定義されたトランザクション コンテキストを使用してキューからメッセージを受信し、キューにメッセージがない場合は、指定した期間で返します。
メッセージの受信に使用するスレッドに外部トランザクション コンテキストが既にアタッチされている場合は、Automatic パラメーターのtransactionTypeを指定します。 メッセージを 1 つの内部トランザクションとして受信する場合は、 Single を指定します。 トランザクション コンテキスト外のトランザクション キューからメッセージを受信する場合は、 None を指定できます。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キュー内の後続のメッセージが返されます。
トランザクション キューからメッセージを受信するためにこのメソッドが呼び出された場合、トランザクションが中止されると、受信したメッセージがキューに返されます。 トランザクションがコミットされるまで、メッセージはキューから完全に削除されません。
キューから削除せずにキュー内の最初のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peek メソッドは常にキュー内の最初のメッセージを返します。そのため、後続のメソッドの呼び出しでは、優先順位の高いメッセージがキューに到着しない限り、同じメッセージが返されます。 Peekの呼び出しによって返されるメッセージに関連付けられたトランザクション コンテキストはありません。 Peekはキュー内のメッセージを削除しないため、Abortの呼び出しによってロールバックするものは何もありません。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 指定した期間、または timeout パラメーターに値InfiniteTimeoutを指定した場合、スレッドは無期限にブロックされます。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(TimeSpan, Cursor, MessageQueueTransaction)
指定したカーソルを使用して、キュー内の現在のメッセージを受信します。 使用できるメッセージがない場合、このメソッドはメッセージが使用可能になるか、タイムアウトが切れるまで待機します。
public:
System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::Cursor ^ cursor, System::Messaging::MessageQueueTransaction ^ transaction);
public System.Messaging.Message Receive(TimeSpan timeout, System.Messaging.Cursor cursor, System.Messaging.MessageQueueTransaction transaction);
member this.Receive : TimeSpan * System.Messaging.Cursor * System.Messaging.MessageQueueTransaction -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, cursor As Cursor, transaction As MessageQueueTransaction) As Message
パラメーター
- transaction
- MessageQueueTransaction
MessageQueueTransaction オブジェクトです。
返品
キュー内のメッセージを参照する Message 。
例外
timeout パラメーターに指定された値は無効です。
timeoutがZeroより小さいか、InfiniteTimeoutより大きい可能性があります。
タイムアウトが切れる前に、メッセージがキューに到着しませんでした。
-または-
キューは非トランザクションです。
-または-
メッセージ キュー メソッドにアクセスするときにエラーが発生しました。
注釈
このオーバーロードを使用して、 transaction パラメーターで定義された内部トランザクション コンテキストを使用してトランザクション キューからメッセージを受信し、キューにメッセージがない場合は、指定した期間内に戻ります。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キューに続くメッセージが返されます。
このメソッドはトランザクション キューで呼び出されるため、トランザクションが中止されると、受信したメッセージがキューに返されます。 トランザクションがコミットされるまで、メッセージはキューから完全に削除されません。
キューからメッセージを削除せずにキュー内のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peekの呼び出しによって返されるメッセージに関連付けられたトランザクション コンテキストはありません。 Peekはキュー内のメッセージを削除しないため、Abortの呼び出しによってロールバックするものはありません。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 指定した期間、または timeout パラメーターの値InfiniteTimeoutを指定した場合、スレッドは無期限にブロックされます。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
Receive(TimeSpan, Cursor, MessageQueueTransactionType)
指定したカーソルを使用して、キュー内の現在のメッセージを受信します。 使用できるメッセージがない場合、このメソッドはメッセージが使用可能になるか、タイムアウトが切れるまで待機します。
public:
System::Messaging::Message ^ Receive(TimeSpan timeout, System::Messaging::Cursor ^ cursor, System::Messaging::MessageQueueTransactionType transactionType);
public System.Messaging.Message Receive(TimeSpan timeout, System.Messaging.Cursor cursor, System.Messaging.MessageQueueTransactionType transactionType);
member this.Receive : TimeSpan * System.Messaging.Cursor * System.Messaging.MessageQueueTransactionType -> System.Messaging.Message
Public Function Receive (timeout As TimeSpan, cursor As Cursor, transactionType As MessageQueueTransactionType) As Message
パラメーター
- transactionType
- MessageQueueTransactionType
メッセージに関連付けるトランザクション コンテキストの種類を表す MessageQueueTransactionType 値の 1 つ。
返品
キュー内のメッセージを参照する Message 。
例外
cursor パラメーターはnull。
timeout パラメーターに指定された値は無効です。
timeoutがZeroより小さいか、InfiniteTimeoutより大きい可能性があります。
transactionType パラメーターは、MessageQueueTransactionType メンバーの 1 つではありません。
注釈
このオーバーロードを使用して、 transactionType パラメーターで定義されたトランザクション コンテキストを使用してキューからメッセージを受信し、キューにメッセージがない場合は、指定した期間で返します。
メッセージの受信に使用するスレッドに外部トランザクション コンテキストが既にアタッチされている場合は、Automatic パラメーターのtransactionTypeを指定します。 メッセージを 1 つの内部トランザクションとして受信する場合は、 Single を指定します。 トランザクション コンテキスト外のトランザクション キューからメッセージを受信する場合は、 None を指定できます。
Receive メソッドを使用すると、メッセージの同期読み取りが可能になり、キューからメッセージを削除できます。 Receiveの後続の呼び出しでは、キューに続くメッセージが返されます。
トランザクション キューからメッセージを受信するためにこのメソッドが呼び出された場合、トランザクションが中止されると、受信したメッセージがキューに返されます。 トランザクションがコミットされるまで、メッセージはキューから完全に削除されません。
キューからメッセージを削除せずにキュー内のメッセージを読み取る場合は、 Peek メソッドを使用します。 Peekの呼び出しによって返されるメッセージに関連付けられたトランザクション コンテキストはありません。 Peekはキュー内のメッセージを削除しないため、Abortの呼び出しによってロールバックするものはありません。
メッセージがキューに到着するのを待機している間に、現在のスレッドがブロックされるのを許容できる場合は、呼び出しを使用して Receive します。 指定した期間、または timeout パラメーターの値InfiniteTimeoutを指定した場合、スレッドは無期限にブロックされます。 メッセージを待たずにアプリケーション処理を続行する必要がある場合は、非同期メソッド ( BeginReceive) の使用を検討してください。
次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。
| ワークグループ モード | 在庫有り |
|---|---|
| ローカル コンピューター | はい |
| ローカル コンピューターと直接の形式名 | はい |
| リモート コンピューター | いいえ |
| リモート コンピューターと直接の形式名 | はい |
こちらもご覧ください
適用対象
スレッド セーフ
このメソッドはスレッド セーフではありません。