Export (0) Print
Expand All

MessageQueue.Receive Method (TimeSpan, Cursor, MessageQueueTransactionType)

Note: This method is new in the .NET Framework version 2.0.

Receives the current message in the queue, using a specified cursor. If no message is available, this method waits until either a message is available, or the time-out expires.

Namespace: System.Messaging
Assembly: System.Messaging (in system.messaging.dll)

public Message Receive (
	TimeSpan timeout,
	Cursor cursor,
	MessageQueueTransactionType transactionType
)
public Message Receive (
	TimeSpan timeout, 
	Cursor cursor, 
	MessageQueueTransactionType transactionType
)
public function Receive (
	timeout : TimeSpan, 
	cursor : Cursor, 
	transactionType : MessageQueueTransactionType
) : Message

Parameters

timeout

A TimeSpan that indicates the time to wait until a new message is available for inspection.

cursor

A Cursor that maintains a specific position in the message queue.

transactionType

One of the MessageQueueTransactionType values that describes the type of transaction context to associate with the message.

Return Value

A Message that references a message in the queue.

Exception typeCondition

ArgumentNullException

The cursor parameter is a null reference (Nothing in Visual Basic).

ArgumentException

The value specified for the timeout parameter is not valid. Possibly timeout is less than TimeSpan.Zero or greater than MessageQueue.InfiniteTimeout.

InvalidEnumArgumentException

The transactionType parameter is not one of the MessageQueueTransactionType members.

MessageQueueException

A message did not arrive in the queue before the time-out expired.

-or-

An error occurred when accessing a Message Queuing method.

Use this overload to receive a message from a queue using a transaction context defined by the transactionType parameter, and return in a specified period of time if there are no messages in the queue.

Specify Automatic for the transactionType parameter if there is already an external transaction context attached to the thread that you want to use to receive the message. Specify Single if you want to receive the message as a single internal transaction. You can specify None if you want to receive a message from a transactional queue outside of a transaction context.

The Receive method allows for the synchronous reading of a message, thereby removing it from the queue. Subsequent calls to Receive return the messages that follow in the queue.

If this method is called to receive a message from a transactional queue, the message that is received is returned to the queue if the transaction is aborted. The message is not permanently removed from the queue until the transaction is committed.

To read a message in a queue without removing it from the queue, use the Peek method. There is no transaction context associated with a message returned by a call to Peek. Because Peek does not remove any messages in the queue, there is nothing to roll back by a call to Abort.

Use a call to Receive when it is acceptable for the current thread to be blocked while it waits for a message to arrive in the queue. The thread is blocked for the given period of time, or indefinitely if you specified the value InfiniteTimeout for the timeout parameter. If the application processing should continue without waiting for a message, consider using the asynchronous method, BeginReceive.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode

Available

Local computer

Yes

Local computer and direct format name

Yes

Remote computer

No

Remote computer and direct format name

Yes

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft