語言

IInputChannel.WaitForMessage(TimeSpan) 方法

定義

回傳一個值,表示訊息是否在指定時間內抵達。

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

參數

timeout
TimeSpan

該 TimeSpan 表示在逾時前,等待訊息到達的最長時間間隔。

傳回

true 若訊息在 被超越之前 timeout 抵達;否則 false。

例外狀況

timeout在操作完成前,規定值已超過。

指定的逾時時間小於零。

範例

以下程式碼說明如何實作此方法:

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

備註

呼叫 WaitForMessage(TimeSpan) 不會讓訊息以其他方式被接收或處理。

此 WaitForMessage(TimeSpan) 方法主要用於使用者希望透過交易接收訊息的交易情境。 若僅用 Receive 正常方式,使用者必須建立交易並撥打 Receive 並希望訊息能在交易逾時前送達,但這可能無法實現。

使用者可以選擇任何時間(甚至無限)撥打 WaitForMessage(TimeSpan) ,當訊息到達時,他們可以開啟交易、撥打 Receive 電話,並有信心能在交易到期前拿回訊息。

此方法為同步式,因此會阻塞當前執行緒,直到訊息可用或逾時發生。 當目前執行緒在等待訊息到達隊列時被封鎖,才會使用 WaitForMessage(TimeSpan) 。 執行緒被阻塞至指定的 timeout。 如果你需要申請流程繼續而不等,請使用非同步 BeginWaitForMessage(TimeSpan, AsyncCallback, Object) 方法。

給實施者的注意事項

如果超過指定false值,該操作才會回傳timeout,而不是逾時例外。

適用於