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.

index 加上 count 大於緩衝區長度。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.

另請參閱

適用於