This documentation is archived and is not being maintained.

MessageQueue.BeginPeek Method (TimeSpan, Object, AsyncCallback)

.NET Framework 1.1

Initiates an asynchronous peek operation that has a specified time-out and a specified state object, which provides associated information throughout the operation's lifetime. This overload receives notification, through a callback, of the identity of the event handler for the operation. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

[Visual Basic]
Overloads Public Function BeginPeek( _
   ByVal timeout As TimeSpan, _
   ByVal stateObject As Object, _
   ByVal callback As AsyncCallback _
) As IAsyncResult
[C#]
public IAsyncResult BeginPeek(
 TimeSpan timeout,
 object stateObject,
 AsyncCallback callback
);
[C++]
public: IAsyncResult* BeginPeek(
 TimeSpan timeout,
 Object* stateObject,
 AsyncCallback* callback
);
[JScript]
public function BeginPeek(
   timeout : TimeSpan,
 stateObject : Object,
 callback : AsyncCallback
) : IAsyncResult;

Parameters

timeout
A TimeSpan that indicates the interval of time to wait for a message to become available.
stateObject
A state object, specified by the application, that contains information associated with the asynchronous operation.
callback
The AsyncCallback that will receive the notification of the asynchronous operation completion.

Return Value

The IAsyncResult that identifies the posted asynchronous request.

Exceptions

Exception Type Condition
ArgumentException The value specified for the timeout parameter is invalid.
MessageQueueException An error occurred when accessing a Message Queuing API.

Remarks

When you use this overload, the callback specified in the callback parameter is invoked directly when a message becomes available in the queue or when the specified interval of time has expired; the PeekCompleted event is not raised. The other overloads of BeginPeek rely on this component to raise the PeekCompleted event.

Note    PeekCompleted is also raised if a message already exists in the queue.
Note   The BeginPeek method returns immediately, but the asynchronous operation is not completed until the event handler is called.

Because BeginPeek is asynchronous, you can call it to peek the queue without blocking the current thread of execution. To synchronously peek the queue, use the Peek method.

Once an asynchronous operation completes, you can call BeginPeek or BeginReceive again in the event handler to keep receiving notifications.

BeginPeek returns an IAsyncResult that identifies the asynchronous operation that the method started. You can use this IAsyncResult throughout the lifetime of the operation, although you generally do not use it until EndPeek is called. However, if you start several asynchronous operations, you can place their IAsyncResult values in an array and specify whether to wait for all operations or any operation to complete. In this case, you use the AsyncWaitHandle property of the IAsyncResult to identify the completed operation.

The state object associates state information with the operation. For example, if you call BeginPeek multiple times to initiate multiple operations, you can identify each operation through a separate state object that you define.

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

Workgroup Mode Available
Local computer Yes
Local computer + direct format name Yes
Remote computer No
Remote computer + direct format name Yes

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.BeginPeek Overload List | EndPeek | PeekCompleted | BeginReceive | Peek | Receive | AsyncCallback | TimeSpan

Show: