Bewerken

Share via


WebSocket.ReceiveAsync Method

Definition

Overloads

ReceiveAsync(ArraySegment<Byte>, CancellationToken)

Receives data from the WebSocket connection asynchronously.

ReceiveAsync(Memory<Byte>, CancellationToken)

Receives data from the WebSocket connection asynchronously.

ReceiveAsync(ArraySegment<Byte>, CancellationToken)

Source:
WebSocket.cs
Source:
WebSocket.cs
Source:
WebSocket.cs

Receives data from the WebSocket connection asynchronously.

public:
 abstract System::Threading::Tasks::Task<System::Net::WebSockets::WebSocketReceiveResult ^> ^ ReceiveAsync(ArraySegment<System::Byte> buffer, System::Threading::CancellationToken cancellationToken);
public abstract System.Threading.Tasks.Task<System.Net.WebSockets.WebSocketReceiveResult> ReceiveAsync (ArraySegment<byte> buffer, System.Threading.CancellationToken cancellationToken);
abstract member ReceiveAsync : ArraySegment<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.WebSockets.WebSocketReceiveResult>
Public MustOverride Function ReceiveAsync (buffer As ArraySegment(Of Byte), cancellationToken As CancellationToken) As Task(Of WebSocketReceiveResult)

Parameters

buffer
ArraySegment<Byte>

References the application buffer that is the storage location for the received data.

cancellationToken
CancellationToken

Propagates the notification that operations should be canceled.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns a WebSocketReceiveResult object that represents the received data.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This operation will not block. The returned Task<TResult> object will complete after the data has been received on the WebSocket.

Exactly one send and one receive is supported on each WebSocket object in parallel. Issuing multiple receives at the same time is not supported and will result in an undefined behavior. You should serialize receive operations via whatever mechanism works best for you, for example, by using a lock or a semaphore.

Applies to

ReceiveAsync(Memory<Byte>, CancellationToken)

Source:
WebSocket.cs
Source:
WebSocket.cs
Source:
WebSocket.cs

Receives data from the WebSocket connection asynchronously.

public:
 virtual System::Threading::Tasks::ValueTask<System::Net::WebSockets::ValueWebSocketReceiveResult> ReceiveAsync(Memory<System::Byte> buffer, System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.ValueTask<System.Net.WebSockets.ValueWebSocketReceiveResult> ReceiveAsync (Memory<byte> buffer, System.Threading.CancellationToken cancellationToken);
abstract member ReceiveAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<System.Net.WebSockets.ValueWebSocketReceiveResult>
override this.ReceiveAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<System.Net.WebSockets.ValueWebSocketReceiveResult>
Public Overridable Function ReceiveAsync (buffer As Memory(Of Byte), cancellationToken As CancellationToken) As ValueTask(Of ValueWebSocketReceiveResult)

Parameters

buffer
Memory<Byte>

The application buffer that is the storage location for the received data.

cancellationToken
CancellationToken

The cancellation token to use to cancel the receive operation.

Returns

The task object representing the asynchronous operation. The Result property on the task object returns a ValueWebSocketReceiveResult object that represents the received data.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Applies to