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.Peek (TimeSpan)

Returns without removing (peeks) 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 Peek( _
   ByVal timeout As TimeSpan _
) As Message
[C#]
public virtual Message Peek(
   TimeSpan timeout
);
[C++]
public: virtual Message* Peek(
   TimeSpan timeout
);
[JScript]
public function Peek(
   timeout : TimeSpan
) : Message;

Parameters

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

Return Value

The Message that represents 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 peek generated an exception specified by the given status message.

Remarks

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

The Peek method allows for the synchronous reading of a message without removing it from the queue. Repeated calls to Peek return the same message unless a higher priority message arrives in the queue. To read a message and remove it from the queue, use the Receive method. Subsequent calls to Receive will return the following messages in the queue or a new, higher priority message.

Use a call to Peek 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.

See Also

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