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.BeginReceive (TimeSpan, Object, AsyncCallback)

Receives the first message available in the queue referenced by the MessageQueue. Waits the specified interval for a new message to be removed, uses the specified object to retrieve the result, and receives notification through a callback.

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

Parameters

timeout
The interval of time, in milliseconds, to wait for a message to be removed.
stateObject
A state object to be marshaled to the thread where the asynchronous operation result is to be retrieved.
callback
The AsyncCallback that will receive the asynchronous operation completion notification.

Return Value

The IAsyncResult that identifies the asynchronous request posted.

Exceptions

Exception Type Condition
ArgumentException The value specified for the timeout parameter is invalid. It may represent a negative number.

Remarks

The state object is used to handle passing information across threads. In an asynchronous scenario, if a thread is started but the callback is on a different thread, the state object is marshaled and passed back along with information from the event. When an asynchronous operation is complete, the delegate you define is called. For example, if you are sending a message to different delegates, you can use this override of the BeginReceive method.

BeginReceive notifies the AsyncCallback delegate when the message has been removed or the timeout has expired. The call to BeginReceive does not block the current thread of execution.

BeginReceive is used in asynchronous processing to notify the AsyncCallback delegate when a message is removed from the queue or the timeout has expired.

Because BeginReceive is asynchronous, you can use this method to peek the queue without blocking the current thread of execution. To peek the queue synchronously, use the Receive method.

See Also

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