MessageQueue.Receive Method (TimeSpan, Cursor)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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


Type: System.TimeSpan

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

Type: System.Messaging.Cursor

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

Return Value

Type: System.Messaging.Message

A Message that references the first message available in the queue.

Exception Condition

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


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


An error occurred when accessing a Message Queuing method

Use this overload to receive a message and return in a specified period of time if there are no messages in the queue.

.NET Framework
Available since 2.0

The method is not thread safe.

Return to top