TryReceive Method

IInputChannel.TryReceive Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Tries to receive a message within a specified interval of time.

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

bool TryReceive(
	TimeSpan timeout,
	out Message message
)

Parameters

timeout
Type: System.TimeSpan
The IAsyncResult returned by a call to one of the BeginReceive(AsyncCallback, Object) methods.
message
Type: System.ServiceModel.Channels.Message %
The Message received.

Return Value

Type: System.Boolean
true if a message is received before the timeout has been exceeded; otherwise false.

ExceptionCondition
TimeoutException

The specified timeout is exceeded before the operation is completed.

ArgumentOutOfRangeException

The timeout specified is less than zero.

If you are going to handle timeouts and not just re-throw or wrap the TimeoutException, then you should call TryReceive(TimeSpan, Message) instead of Receive.

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

The following code shows how to implement this method.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft