Share via


IReplyChannel.WaitForRequest(TimeSpan) 方法

定义

返回一个值,该值指示是否在经历指定的时间间隔之前接收到请求消息。

public:
 bool WaitForRequest(TimeSpan timeout);
public bool WaitForRequest (TimeSpan timeout);
abstract member WaitForRequest : TimeSpan -> bool
Public Function WaitForRequest (timeout As TimeSpan) As Boolean

参数

timeout
TimeSpan

一个 TimeSpan,指定请求操作的完成时限,在此时限之后操作将超时并返回 false

返回

如果在经历指定的时间间隔之前接收到请求,则为 true;否则为 false

示例

下面的代码演示如何实现此方法:

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

注解

调用 WaitForRequest(TimeSpan) 不会导致以任何方式接收或处理请求消息。

BeginWaitForRequest(TimeSpan, AsyncCallback, Object) 方法主要用于用户要使用事务接收消息的事务处理方案。 在通常只需要为此使用 ReceiveRequest 时,用户必须创建事务,然后调用 ReceiveRequest 并希望消息在事务超时前到达,但这可能不可行。

用户可以改为调用 WaitForRequest(TimeSpan) 并指定超时值(甚至是无限超时值),接着在消息到达时,可以打开事务,调用 ReceiveRequest 并确信它们能在事务过期前取回消息。

如果当前线程在等待消息到达队列时可以被阻塞,则使用 WaitForRequest(TimeSpan)。 该线程最多被阻塞 timeout 指定的时间长度。 如果需要应用程序处理继续进行而不等待,则使用异步 BeginWaitForRequest(TimeSpan, AsyncCallback, Object) 方法。

实施者说明

如果超出指定的 false,此操作返回 timeout

适用于