Export (0) Print
Expand All

IInputChannel.WaitForMessage Method

Returns a value that indicates whether a message has arrived within a specified interval of time.

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

bool WaitForMessage(
	TimeSpan timeout
)

Parameters

timeout
Type: System.TimeSpan

The Timespan specifies the maximum interval of time to wait for a message to arrive before timing out.

Return Value

Type: System.Boolean
true if a message has arrived 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.

Calling WaitForMessage(TimeSpan) does not result in a message being received or processed in any other way.

The WaitForMessage(TimeSpan) method exists primarily for transacted scenarios where the user wants to receive the message using a transaction. When using just Receive normally for this, the user must create the transaction and then call Receive and hope the message arrives before the transaction times out, which may not be possible.

Instead, the user can call WaitForMessage(TimeSpan) with whatever time out they want (even infinite), then when a message arrives they can open the transaction, call Receive and be confident that they can get the message back before the transaction expires.

This method is synchronous, so it blocks the current thread until a message is available or the time out occurs. Use WaitForMessage(TimeSpan) when it is acceptable for the current thread to be blocked while it waits for a message to arrive in the queue. The thread is blocked up to the specified timeout. If you need the application processing to continue without waiting, use the asynchronous BeginWaitForMessage(TimeSpan, AsyncCallback, Object) method.

Notes to Implementers

The operation returns false if the specified timeout is exceeded, not a timeout exception.

The following code illustrates how to implement this method:

public bool WaitForMessage(TimeSpan timeout)
{
    return this.InnerChannel.WaitForMessage(timeout);
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft