Muokkaa

Jaa


TextWriter.WriteAsync Method

Definition

Writes data to the text stream asynchronously.

Overloads

WriteAsync(Char[], Int32, Int32)

Writes a subarray of characters to the text stream asynchronously.

WriteAsync(StringBuilder, CancellationToken)

Asynchronously writes a string builder to the text stream.

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

Asynchronously writes a character memory region to the text stream.

WriteAsync(String)

Writes a string to the text stream asynchronously.

WriteAsync(Char[])

Writes a character array to the text stream asynchronously.

WriteAsync(Char)

Writes a character to the text stream asynchronously.

WriteAsync(Char[], Int32, Int32)

Source:
TextWriter.cs
Source:
TextWriter.cs
Source:
TextWriter.cs

Writes a subarray of characters to the text stream asynchronously.

public:
 virtual System::Threading::Tasks::Task ^ WriteAsync(cli::array <char> ^ buffer, int index, int count);
public virtual System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
abstract member WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
Public Overridable Function WriteAsync (buffer As Char(), index As Integer, count As Integer) As Task

Parameters

buffer
Char[]

The character array to write data from.

index
Int32

The character position in the buffer at which to start retrieving data.

count
Int32

The number of characters to write.

Returns

A task that represents the asynchronous write operation.

Attributes

Exceptions

buffer is null.

The index plus count is greater than the buffer length.

index or count is negative.

The text writer is disposed.

The text writer is currently in use by a previous write operation.

Remarks

The TextWriter class is an abstract class. Therefore, you do not instantiate it in your code. For an example of using the WriteAsync method, see the StreamWriter.WriteAsync method.

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(Char[], Int32, Int32).

See also

Applies to

WriteAsync(StringBuilder, CancellationToken)

Source:
TextWriter.cs
Source:
TextWriter.cs
Source:
TextWriter.cs

Asynchronously writes a string builder to the text stream.

public virtual System.Threading.Tasks.Task WriteAsync (System.Text.StringBuilder? value, System.Threading.CancellationToken cancellationToken = default);
abstract member WriteAsync : System.Text.StringBuilder * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.WriteAsync : System.Text.StringBuilder * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function WriteAsync (value As StringBuilder, Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

value
StringBuilder

The string, as a string builder, to write to the text stream.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

A task that represents the asynchronous write operation.

Exceptions

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

Remarks

This method is equivalent to calling WriteAsync(stringBuilder.ToString()), however, it uses the StringBuilder.GetChunks() method to avoid creating the intermediate string.

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(StringBuilder).

Applies to

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

Source:
TextWriter.cs
Source:
TextWriter.cs
Source:
TextWriter.cs

Asynchronously writes a character memory region to the text stream.

public virtual System.Threading.Tasks.Task WriteAsync (ReadOnlyMemory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
abstract member WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function WriteAsync (buffer As ReadOnlyMemory(Of Char), Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

buffer
ReadOnlyMemory<Char>

The character memory region to write to the text stream.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

A task that represents the asynchronous write operation.

Exceptions

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

Applies to

WriteAsync(String)

Source:
TextWriter.cs
Source:
TextWriter.cs
Source:
TextWriter.cs

Writes a string to the text stream asynchronously.

public:
 virtual System::Threading::Tasks::Task ^ WriteAsync(System::String ^ value);
public virtual System.Threading.Tasks.Task WriteAsync (string value);
public virtual System.Threading.Tasks.Task WriteAsync (string? value);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task WriteAsync (string value);
abstract member WriteAsync : string -> System.Threading.Tasks.Task
override this.WriteAsync : string -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member WriteAsync : string -> System.Threading.Tasks.Task
override this.WriteAsync : string -> System.Threading.Tasks.Task
Public Overridable Function WriteAsync (value As String) As Task

Parameters

value
String

The string to write. If value is null, nothing is written to the text stream.

Returns

A task that represents the asynchronous write operation.

Attributes

Exceptions

The text writer is disposed.

The text writer is currently in use by a previous write operation.

Remarks

The TextWriter class is an abstract class. Therefore, you do not instantiate it in your code. For an example of using the WriteAsync method, see the StreamWriter.WriteAsync method.

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(String).

See also

Applies to

WriteAsync(Char[])

Source:
TextWriter.cs
Source:
TextWriter.cs
Source:
TextWriter.cs

Writes a character array to the text stream asynchronously.

public:
 System::Threading::Tasks::Task ^ WriteAsync(cli::array <char> ^ buffer);
public System.Threading.Tasks.Task WriteAsync (char[] buffer);
public System.Threading.Tasks.Task WriteAsync (char[]? buffer);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task WriteAsync (char[] buffer);
member this.WriteAsync : char[] -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.WriteAsync : char[] -> System.Threading.Tasks.Task
Public Function WriteAsync (buffer As Char()) As Task

Parameters

buffer
Char[]

The character array to write to the text stream. If buffer is null, nothing is written.

Returns

A task that represents the asynchronous write operation.

Attributes

Exceptions

The text writer is disposed.

The text writer is currently in use by a previous write operation.

Remarks

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(Char[]).

See also

Applies to

WriteAsync(Char)

Source:
TextWriter.cs
Source:
TextWriter.cs
Source:
TextWriter.cs

Writes a character to the text stream asynchronously.

public:
 virtual System::Threading::Tasks::Task ^ WriteAsync(char value);
public virtual System.Threading.Tasks.Task WriteAsync (char value);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task WriteAsync (char value);
abstract member WriteAsync : char -> System.Threading.Tasks.Task
override this.WriteAsync : char -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member WriteAsync : char -> System.Threading.Tasks.Task
override this.WriteAsync : char -> System.Threading.Tasks.Task
Public Overridable Function WriteAsync (value As Char) As Task

Parameters

value
Char

The character to write to the text stream.

Returns

A task that represents the asynchronous write operation.

Attributes

Exceptions

The text writer is disposed.

The text writer is currently in use by a previous write operation.

Remarks

The TextWriter class is an abstract class. Therefore, you do not instantiate it in your code. For an example of using the WriteAsync method, see the StreamWriter.WriteAsync method.

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(Char).

See also

Applies to