IInputChannel.WaitForMessage(TimeSpan) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a value that indicates whether a message has arrived within a specified interval of time.
public:
bool WaitForMessage(TimeSpan timeout);
public bool WaitForMessage (TimeSpan timeout);
abstract member WaitForMessage : TimeSpan -> bool
Public Function WaitForMessage (timeout As TimeSpan) As Boolean
Parameters
- timeout
- TimeSpan
The TimeSpan specifies the maximum interval of time to wait for a message to arrive before timing out.
Returns
true
if a message has arrived before the timeout
has been exceeded; otherwise false
.
Exceptions
The specified timeout
is exceeded before the operation is completed.
The timeout specified is less than zero.
Examples
The following code illustrates how to implement this method:
public bool WaitForMessage(TimeSpan timeout)
{
return this.InnerChannel.WaitForMessage(timeout);
}
Remarks
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.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기