Export (0) Print
Expand All

MessageQueue.BeginPeek Method (TimeSpan, Cursor, PeekAction, Object, AsyncCallback)

Initiates an asynchronous peek operation that has a specified time-out and that uses a specified cursor, a specified peek action, and a specified state object. The state object provides associated information throughout the lifetime of the operation. 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.

Namespace: System.Messaging
Assembly: System.Messaging (in system.messaging.dll)

public IAsyncResult BeginPeek (
	TimeSpan timeout,
	Cursor cursor,
	PeekAction action,
	Object state,
	AsyncCallback callback
)
public IAsyncResult BeginPeek (
	TimeSpan timeout, 
	Cursor cursor, 
	PeekAction action, 
	Object state, 
	AsyncCallback callback
)
public function BeginPeek (
	timeout : TimeSpan, 
	cursor : Cursor, 
	action : PeekAction, 
	state : Object, 
	callback : AsyncCallback
) : IAsyncResult
Not applicable.

Parameters

timeout

A TimeSpan that indicates the interval of time to wait for a message to become available.

cursor

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

action

One of the PeekAction values. Indicates whether to peek at the current message in the queue, or the next message.

state

A state object, specified by the application, that contains information associated with the asynchronous operation.

callback

The AsyncCallback that receives the notification of the asynchronous operation completion.

Return Value

The IAsyncResult that identifies the posted asynchronous request.

Exception typeCondition

ArgumentOutOfRangeException

A value other than PeekAction.Current or PeekAction.Next was specified for the action parameter.

ArgumentNullException

The cursor parameter is a null reference (Nothing in Visual Basic).

ArgumentException

The value specified for the timeout parameter is not valid.

MessageQueueException

An error occurred when accessing a Message Queuing method.

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.

PeekCompleted is also raised if a message already exists in the queue.

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 a IAsyncResult that identifies the asynchronous operation started by the method. 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, 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 and direct format name

Yes

Remote computer

No

Remote computer and direct format name

Yes

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft