IReplyChannel.BeginTryReceiveRequest(TimeSpan, AsyncCallback, Object) 方法

定義

開始非同步的作業,接收具有已指定逾時以及與該作業關聯之狀態物件的要求訊息。Begins an asynchronous operation to receive a request message that has a specified time out and state object associated with it.

public:
 IAsyncResult ^ BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginTryReceiveRequest (TimeSpan timeout, AsyncCallback callback, object state);
abstract member BeginTryReceiveRequest : TimeSpan * AsyncCallback * obj -> IAsyncResult
Public Function BeginTryReceiveRequest (timeout As TimeSpan, callback As AsyncCallback, state As Object) As IAsyncResult

參數

timeout
TimeSpan

TimeSpan,指定必須在逾時和傳回 false 多久之前完成接收要求作業。The TimeSpan that specifies how long the receive request operation has to complete before timing out and returning false.

callback
AsyncCallback

AsyncCallback 委派,這個委派會接收要求作業完成之非同步接收的通知。The AsyncCallback delegate that receives the notification of the asynchronous receive that a request operation completes.

state
Object

應用程式所指定的物件,其中包含與要求作業之非同步接收相關聯的狀態資訊。An object, specified by the application, that contains state information associated with the asynchronous receive of a request operation.

傳回

IAsyncResult,參考非同步接收要求作業。The IAsyncResult that references the asynchronous receive request operation.

範例

下列程式碼說明如何實作這個方法:The following code illustrates how to implement this method:

public IAsyncResult BeginTryReceiveRequest(TimeSpan timeout, AsyncCallback callback, object state)
{
    TryReceiveRequestAsyncResult result = new TryReceiveRequestAsyncResult(this, timeout, callback, state);
    result.Begin();
    return result;
}

備註

當您需要應用程式繼續執行而不要等候時,請使用非同步的 BeginTryReceiveRequest(TimeSpan, AsyncCallback, Object) 方法。Use the asynchronous BeginTryReceiveRequest(TimeSpan, AsyncCallback, Object) method when you need the application processing to continue without waiting. 當目前的執行緒可接受進行封鎖並同時回覆要求訊息,或是直到已超過逾時間隔時,請使用其中一種同步的 TryReceiveRequest(TimeSpan, RequestContext) 方法。Use one of the synchronous TryReceiveRequest(TimeSpan, RequestContext) methods when it is acceptable for the current thread to be blocked while it replies to the request message or until the timeout interval is exceeded.

這個方法會透過回呼 (Callback),接收有關作業之事件處理常式身分識別的通知。This method receives notification, through a callback, of the identity of the event handler for the operation. 在訊息可以於通道中使用或發生逾時之後,作業才會完成。The operation is not complete until either a message becomes available in the channel or the time out occurs.

給實施者的注意事項

如果超出了指定的 false,作業會傳回 timeoutThe operation returns false if the specified timeout is exceeded.

適用於