RandomAccess.WriteAsync 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.
Overloads
WriteAsync(SafeFileHandle, IReadOnlyList<ReadOnlyMemory<Byte>>, Int64, CancellationToken) |
Writes a sequence of bytes from given buffers to given file at given offset. |
WriteAsync(SafeFileHandle, ReadOnlyMemory<Byte>, Int64, CancellationToken) |
Writes a sequence of bytes from given buffer to given file at given offset. |
WriteAsync(SafeFileHandle, IReadOnlyList<ReadOnlyMemory<Byte>>, Int64, CancellationToken)
- Source:
- RandomAccess.cs
- Source:
- RandomAccess.cs
- Source:
- RandomAccess.cs
Writes a sequence of bytes from given buffers to given file at given offset.
public static System.Threading.Tasks.ValueTask WriteAsync (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.Collections.Generic.IReadOnlyList<ReadOnlyMemory<byte>> buffers, long fileOffset, System.Threading.CancellationToken cancellationToken = default);
static member WriteAsync : Microsoft.Win32.SafeHandles.SafeFileHandle * System.Collections.Generic.IReadOnlyList<ReadOnlyMemory<byte>> * int64 * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Public Shared Function WriteAsync (handle As SafeFileHandle, buffers As IReadOnlyList(Of ReadOnlyMemory(Of Byte)), fileOffset As Long, Optional cancellationToken As CancellationToken = Nothing) As ValueTask
Parameters
- handle
- SafeFileHandle
The file handle.
- buffers
- IReadOnlyList<ReadOnlyMemory<Byte>>
A list of memory buffers. This method copies the contents of these buffers to the file.
- fileOffset
- Int64
The file position to write to.
- cancellationToken
- CancellationToken
The token to monitor for cancellation requests. The default value is None.
Returns
A task representing the asynchronous completion of the write operation.
Exceptions
handle
or buffers
is null
.
handle
is invalid.
The file is closed.
The file does not support seeking (pipe or socket).
fileOffset
is negative.
handle
was not opened for writing.
An I/O error occurred.
The cancellation token was canceled. This exception is stored into the returned task.
Remarks
Position of the file is not advanced.
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 as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Write(SafeFileHandle, IReadOnlyList<ReadOnlyMemory<Byte>>, Int64).
Applies to
WriteAsync(SafeFileHandle, ReadOnlyMemory<Byte>, Int64, CancellationToken)
- Source:
- RandomAccess.cs
- Source:
- RandomAccess.cs
- Source:
- RandomAccess.cs
Writes a sequence of bytes from given buffer to given file at given offset.
public static System.Threading.Tasks.ValueTask WriteAsync (Microsoft.Win32.SafeHandles.SafeFileHandle handle, ReadOnlyMemory<byte> buffer, long fileOffset, System.Threading.CancellationToken cancellationToken = default);
static member WriteAsync : Microsoft.Win32.SafeHandles.SafeFileHandle * ReadOnlyMemory<byte> * int64 * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Public Shared Function WriteAsync (handle As SafeFileHandle, buffer As ReadOnlyMemory(Of Byte), fileOffset As Long, Optional cancellationToken As CancellationToken = Nothing) As ValueTask
Parameters
- handle
- SafeFileHandle
The file handle.
- buffer
- ReadOnlyMemory<Byte>
A region of memory. This method copies the contents of this region to the file.
- fileOffset
- Int64
The file position to write to.
- cancellationToken
- CancellationToken
The token to monitor for cancellation requests. The default value is None.
Returns
A task representing the asynchronous completion of the write operation.
Exceptions
handle
is null
.
handle
is invalid.
The file is closed.
The file does not support seeking (pipe or socket).
fileOffset
is negative.
handle
was not opened for writing.
An I/O error occurred.
The cancellation token was canceled. This exception is stored into the returned task.
Remarks
Position of the file is not advanced.