Redigera

Dela via


IInputChannel.BeginReceive Method

Definition

Begins an asynchronous receive operation.

Overloads

BeginReceive(AsyncCallback, Object)

Begins an asynchronous operation to receive a message that has a state object associated with it.

BeginReceive(TimeSpan, AsyncCallback, Object)

Begins an asynchronous operation to receive a message that has a specified time out and state object associated with it.

Remarks

Use the asynchronous BeginReceive method when you want the application processing to continue without waiting for the request to be received. Use the synchronous Receive method when it is acceptable for the current thread to be blocked until the request message is received or the interval of time specified by the timeout has been exceeded. The asynchronous operation is available with or without an explicit timeout.

BeginReceive(AsyncCallback, Object)

Source:
IInputChannel.cs
Source:
IInputChannel.cs

Begins an asynchronous operation to receive a message that has a state object associated with it.

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

Parameters

callback
AsyncCallback

The AsyncCallback delegate that receives the notification of the asynchronous operation completion.

state
Object

An object, specified by the application, that contains state information associated with the asynchronous operation.

Returns

The IAsyncResult that references the asynchronous message reception.

Examples

The following code illustrates how to implement this method:

public IAsyncResult BeginReceive(AsyncCallback callback, object state)
{
    return BeginReceive(DefaultReceiveTimeout, callback, state);
}

Remarks

Use the asynchronous BeginReceive method when you want the application processing to continue without waiting for the request to be received. Use the synchronous Receive method when it is acceptable for the current thread to be blocked until the request message is received or the interval of time specified by the timeout has been exceeded. The asynchronous operation is available with or without an explicit timeout.

This method receives notification, through a callback, of the identity of the event handler for the operation. The operation is not complete until a message becomes available in the channel.

Applies to

BeginReceive(TimeSpan, AsyncCallback, Object)

Source:
IInputChannel.cs
Source:
IInputChannel.cs

Begins an asynchronous operation to receive a message that has a specified time out and state object associated with it.

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

Parameters

timeout
TimeSpan

The TimeSpan that specifies the interval of time to wait for a message to become available.

callback
AsyncCallback

The AsyncCallback delegate that receives the notification of the asynchronous operation completion.

state
Object

An object, specified by the application, that contains state information associated with the asynchronous operation.

Returns

The IAsyncResult that references the asynchronous receive operation.

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 IAsyncResult BeginReceive(TimeSpan timeout, AsyncCallback callback, object state)
{
    ReceiveAsyncResult<TChannel> result = new ReceiveAsyncResult<TChannel>(this, timeout, callback, state);
    result.Begin();
    return result;
}

Remarks

Use the asynchronous BeginReceive method when you want the application processing to continue without waiting for the request to be received. Use the synchronous Receive method when it is acceptable for the current thread to be blocked until the request message is received or the interval of time specified by the timeout has been exceeded. The asynchronous operation is available with or without an explicit timeout.

The operation is not complete until either a message becomes available in the channel or the time out occurs.

Notes to Implementers

The operation throws a TimeoutException if the specified timeout is exceeded before it completes.

Applies to