This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
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.
| Name | Description |
|---|---|
| WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) | Writes data to theNetworkStream from a read-only memory byte memory range as an asynchronous operation. |
| WriteAsync(Byte[], Int32, Int32, CancellationToken) | Writes data to theNetworkStream from the specified range of a byte array as an asynchronous operation. |
Writes data to theNetworkStream from a read-only memory byte memory range as an asynchronous operation.
public override System.Threading.Tasks.ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, System.Threading.CancellationToken cancellationToken = default);override this.WriteAsync : ReadOnlyMemory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTaskPublic Overrides Function WriteAsync (buffer As ReadOnlyMemory(Of Byte), Optional cancellationToken As CancellationToken = Nothing) As ValueTaskA region of memory that contains the data to write to theNetworkStream.
The token to monitor for cancellation requests.
A task that represents the asynchronous write operation.
TheNetworkStream does not support writing.
An error occurred when accessing the socket.
-or-
There was a failure while writing to the network.
TheNetworkStream is closed.
The cancellation token was canceled. This exception is stored into the returned task.
This method sends all bytes inbuffer to the network.
Note
Check to see if theNetworkStream is writable by calling theCanWrite property. If you attempt to write to aNetworkStream that is not writable, you will get anInvalidOperationException.
Note
If you receive anIOException, check theInnerException property to determine if it was caused by aSocketException. If so, use theErrorCode property to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
Writes data to theNetworkStream from the specified range of a byte array as an asynchronous operation.
public: override System::Threading::Tasks::Task ^ WriteAsync(cli::array <System::Byte> ^ buffer, int offset, int count, System::Threading::CancellationToken cancellationToken);public: override System::Threading::Tasks::Task ^ WriteAsync(cli::array <System::Byte> ^ buffer, int offset, int size, System::Threading::CancellationToken cancellationToken);public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken);public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int size, System.Threading.CancellationToken cancellationToken);override this.WriteAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Taskoverride this.WriteAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.TaskPublic Overrides Function WriteAsync (buffer As Byte(), offset As Integer, count As Integer, cancellationToken As CancellationToken) As TaskPublic Overrides Function WriteAsync (buffer As Byte(), offset As Integer, size As Integer, cancellationToken As CancellationToken) As TaskA byte array that contains the data to write to theNetworkStream.
The location inbuffer from which to start writing data.
The number of bytes to write to theNetworkStream.
The token to monitor for cancellation requests.
A task that represents the asynchronous write operation.
Thebuffer parameter isnull.
Theoffset parameter is less than 0.
-or-
Theoffset parameter is greater than the length ofbuffer.
-or-
Thesize parameter is less than 0.
-or-
Thesize parameter is greater than the length ofbuffer minus the value of theoffset parameter.
TheNetworkStream does not support writing.
There was a failure while writing to the network.
-or-
An error occurred when accessing the socket.
TheNetworkStream is closed.
The cancellation token was canceled. This exception is stored into the returned task.
This method starts at the specifiedoffset and sendscount bytes from the contents ofbuffer to the network.
Note
Check to see if theNetworkStream is writable by calling theCanWrite property. If you attempt to write to aNetworkStream that is not writable, you will get anInvalidOperationException.
Note
If you receive anIOException, check theInnerException property to determine if it was caused by aSocketException. If so, use theErrorCode property to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such asArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown byWrite(Byte[], Int32, Int32).
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?