Editare

Partajați prin


IReplyChannel.TryReceiveRequest(TimeSpan, RequestContext) Method

Definition

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

public:
 bool TryReceiveRequest(TimeSpan timeout, [Runtime::InteropServices::Out] System::ServiceModel::Channels::RequestContext ^ % context);
public bool TryReceiveRequest (TimeSpan timeout, out System.ServiceModel.Channels.RequestContext context);
abstract member TryReceiveRequest : TimeSpan * RequestContext -> bool
Public Function TryReceiveRequest (timeout As TimeSpan, ByRef context As RequestContext) As Boolean

Parameters

timeout
TimeSpan

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

context
RequestContext

The RequestContext received.

Returns

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

Examples

The following code illustrates how to implement this method:

public bool TryReceiveRequest(TimeSpan timeout, out RequestContext requestContext)
{
    bool result;

    while (true)
    {
        result = this.InnerChannel.TryReceiveRequest(timeout, out requestContext);
        if (!result || ProcessRequestContext(ref requestContext))
        {
            break;
        }
    }

    return result;
}

Remarks

Use TryReceiveRequest(TimeSpan, RequestContext) when it is acceptable for the current thread to be blocked while it waits for a request 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 BeginTryReceiveRequest(TimeSpan, AsyncCallback, Object) method.

Notes to Implementers

The operation returns false if the specified timeout is exceeded.

Applies to