NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

MessageQueue.Receive (TimeSpan)

Receives the first message available in the queue referenced by the MessageQueue. Waits the specified interval for a message to become available.

[Visual Basic]
Overloads Overridable Public Function Receive( _
   ByVal timeout As TimeSpan _
) As Message
[C#]
public virtual Message Receive(
   TimeSpan timeout
);
[C++]
public: virtual Message* Receive(
   TimeSpan timeout
);
[JScript]
public function Receive(
   timeout : TimeSpan
) : Message;

Parameters

timeout
The interval of time, in milliseconds, to wait for a message to become available.

Return Value

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

Exceptions

Exception Type Condition
ArgumentException The value specified for the timeout parameter is invalid. It may represent a negative number.
MessageQueueException The attempt to unlock the queue in order to retrieve the contents generated an exception specified by the given status.

Remarks

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

The Receive method allows for the synchronous reading of a message, removing it from the queue. Subsequent calls to Receive will return the messages that follow in the queue,k or a new, higher priority message.

To read the first message in a queue without removing it from the queue, use the Peek method. The Peek method always returns the first message in the queue, so subsequent calls to the method return the same message unless a higher priority message arrives in the queue.

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 will be blocked for the given period of time, or indefinitely if you specified System.Messaging.MessageQueue.Infinite. If the application processing should continue without waiting for a message, consider using the asynchronous method, BeginPeek.

Example

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.Receive Overload List | Peek | InfiniteTimeout | BeginReceive | BeginPeek