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;
The Message that represents first message available in the queue.
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. |
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.
MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.Peek Overload List | Receive | InfiniteTimeout | BeginPeek | BeginReceive