IInputChannel::TryReceive Method (TimeSpan, Message^%)
Tries to receive a message within a specified interval of time.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Parameters
- timeout
-
Type:
System::TimeSpan
The IAsyncResult returned by a call to one of the BeginReceive methods.
- message
-
Type:
System.ServiceModel.Channels::Message^%
The Message received.
Return Value
Type: System::Booleantrue if a message is received before the timeout has been exceeded; otherwise false.
| Exception | Condition |
|---|---|
| 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 just call Receive, otherwise you will lose error information.
The following code illustrates how to implement this method:
public bool TryReceive(TimeSpan timeout, out Message message) { bool result; while (true) { result = this.InnerChannel.TryReceive(timeout, out message); if (ProcessReceivedMessage(ref message)) { break; } } return result; }
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0