TextWriter.WriteAsync 方法

定义

将数据异步写入文本流。Writes data to the text stream asynchronously.

重载

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)

以异步形式将字符的子数组写入文本流。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);
[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
Public Overridable Function WriteAsync (buffer As Char(), index As Integer, count As Integer) As Task

参数

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.

返回

表示异步写入操作的任务。A task that represents the asynchronous write operation.

属性

异常

buffernullbuffer is null.

indexcount 大于缓冲区长度。The index plus count is greater than the buffer length.

indexcount 为负数。index or count is negative.

文本编写器已被释放。The text writer is disposed.

文本编写器正在由其前一次写操作使用。The text writer is currently in use by a previous write operation.

注解

TextWriter 类是抽象类。The TextWriter class is an abstract class. 因此,不要在代码中对其进行实例化。Therefore, you do not instantiate it in your code. 有关使用WriteAsync方法的示例, StreamWriter.WriteAsync请参见方法。For an example of using the WriteAsync method, see the StreamWriter.WriteAsync method.

另请参阅

WriteAsync(StringBuilder, CancellationToken)

以异步形式将字符串生成器写入文本流。Asynchronously writes a string builder to the text stream.

public virtual System.Threading.Tasks.Task WriteAsync (System.Text.StringBuilder value, System.Threading.CancellationToken cancellationToken = null);
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

参数

value
StringBuilder

要作为字符串生成器写入文本流的字符串。The string, as a string builder, to write to the text stream.

cancellationToken
CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests. 默认值为 NoneThe default value is None.

返回

表示异步写入操作的任务。A task that represents the asynchronous write operation.

注解

此方法等效于调用WriteAsync(stringBuilder.ToString()),但是,它StringBuilder.GetChunks()使用方法来避免创建中间字符串。This method is equivalent to calling WriteAsync(stringBuilder.ToString()), however, it uses the StringBuilder.GetChunks() method to avoid creating the intermediate string.

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

以异步形式将字符内存区域写入文本流。Asynchronously writes a character memory region to the text stream.

public virtual System.Threading.Tasks.Task WriteAsync (ReadOnlyMemory<char> buffer, System.Threading.CancellationToken cancellationToken = null);
abstract member WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task

参数

buffer
ReadOnlyMemory<Char>

要写入文本流中的字符内存区域。The character memory region to write to the text stream.

cancellationToken
CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests. 默认值为 NoneThe default value is None.

返回

表示异步写入操作的任务。A task that represents the asynchronous write operation.

WriteAsync(String)

将字符串异步写入文本流。Writes a string to the text stream asynchronously.

public:
 virtual System::Threading::Tasks::Task ^ WriteAsync(System::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
Public Overridable Function WriteAsync (value As String) As Task

参数

value
String

要写入的字符串。The string to write. 如果 valuenull,则不会将任何内容写入文本流。If value is null, nothing is written to the text stream.

返回

表示异步写入操作的任务。A task that represents the asynchronous write operation.

属性

异常

文本编写器已被释放。The text writer is disposed.

文本编写器正在由其前一次写操作使用。The text writer is currently in use by a previous write operation.

注解

TextWriter 类是抽象类。The TextWriter class is an abstract class. 因此,不要在代码中对其进行实例化。Therefore, you do not instantiate it in your code. 有关使用WriteAsync方法的示例, StreamWriter.WriteAsync请参见方法。For an example of using the WriteAsync method, see the StreamWriter.WriteAsync method.

另请参阅

WriteAsync(Char[])

将字符数组异步写入文本流。Writes a character array to the text stream asynchronously.

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

参数

buffer
Char[]

要写入文本流中的字符数组。The character array to write to the text stream. 如果 buffernull,则不写入任何内容。If buffer is null, nothing is written.

返回

表示异步写入操作的任务。A task that represents the asynchronous write operation.

属性

异常

文本编写器已被释放。The text writer is disposed.

文本编写器正在由其前一次写操作使用。The text writer is currently in use by a previous write operation.

另请参阅

WriteAsync(Char)

将字符异步写入文本流。Writes a character to the text stream asynchronously.

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
Public Overridable Function WriteAsync (value As Char) As Task

参数

value
Char

要写入文本流中的字符。The character to write to the text stream.

返回

表示异步写入操作的任务。A task that represents the asynchronous write operation.

属性

异常

文本编写器已被释放。The text writer is disposed.

文本编写器正在由其前一次写操作使用。The text writer is currently in use by a previous write operation.

注解

TextWriter 类是抽象类。The TextWriter class is an abstract class. 因此,不要在代码中对其进行实例化。Therefore, you do not instantiate it in your code. 有关使用WriteAsync方法的示例, StreamWriter.WriteAsync请参见方法。For an example of using the WriteAsync method, see the StreamWriter.WriteAsync method.

另请参阅

适用于