IReplyChannel.WaitForRequest Method (TimeSpan)


Returns a value that indicates whether a request message is received before a specified interval of time elapses.

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

bool WaitForRequest(
	TimeSpan timeout


Type: System.TimeSpan

The TimeSpan that specifies how long a request operation has to complete before timing out and returning false.

Return Value

Type: System.Boolean

true if a request is received before the specified interval of time elapses; otherwise false.

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

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

Instead, the user can call WaitForRequest(TimeSpan) and specify the time out (even infinite), then when a message arrives they can open the transaction, call ReceiveRequest and be confident that they can get the message back before the transaction expires.

Use WaitForRequest(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 BeginWaitForRequest(TimeSpan, AsyncCallback, Object) method.

Notes to Implementers:

The operation returns false if the specified timeout is exceeded.

The following code illustrates how to implement this method:

public bool WaitForRequest(TimeSpan timeout)
    return this.InnerChannel.WaitForRequest(timeout);

.NET Framework
Available since 3.0
Return to top