Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
BeginTryReceive Method

IInputChannel.BeginTryReceive Method

Begins an asynchronous operation to receive a message that has a specified time out and state object associated with it.

Namespace: System.ServiceModel.Channels
Assembly: System.ServiceModel (in system.servicemodel.dll)

IAsyncResult BeginTryReceive (
	TimeSpan timeout,
	AsyncCallback callback,
	Object state
IAsyncResult BeginTryReceive (
	TimeSpan timeout, 
	AsyncCallback callback, 
	Object state
function BeginTryReceive (
	timeout : TimeSpan, 
	callback : AsyncCallback, 
	state : Object
) : IAsyncResult
Not applicable.



The Timespan that specifies the interval of time to wait for a message to become available.


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


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

Return Value

The IAsyncResult that references the asynchronous receive operation.

Exception typeCondition


The specified timeout is exceeded before the operation is completed.


The timeout specified is less than zero.

Use the asynchronous BeginTryReceive method when you want the application processing to continue without waiting. Use the synchronous TryReceive method when it is acceptable for the current thread to be blocked while it replies to the request message or until the timeout interval is exceeded.

The operation is not complete until either a message becomes available in the channel or the timeout occurs.

If you are going to handle timeouts and not just re-throw or wrap the TimeoutException, then you should call BeginTryReceive instead of BeginReceive.

If you are not going to treat timeouts specially then just call BeginReceive, otherwise you lose error information.

Notes to Implementers: The operation returns false from EndTryReceive if the specified timeout is exceeded.

The following code illustrates how to implement this method:

public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
    TryReceiveAsyncResult<TChannel> result = new TryReceiveAsyncResult<TChannel>(this, timeout, callback, state);
    return result;

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

Community Additions

© 2015 Microsoft