共用方式為


IInputChannel.TryReceive Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Function TryReceive ( _
    timeout As TimeSpan, _
    <OutAttribute> ByRef message As Message _
) As Boolean
bool TryReceive(
    TimeSpan timeout,
    out Message message
)

Parameters

Return Value

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

Exceptions

Exception Condition
TimeoutException

The specified timeout is exceeded before the operation is completed.

ArgumentOutOfRangeException

The timeout specified is less than zero.

Remarks

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.

Examples

The following code shows how to implement this method.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.