StreamWriter.WriteAsync メソッド
定義
データをストリームに非同期で書き込みます。Asynchronously writes data to the stream.
オーバーロード
WriteAsync(Char) |
文字を非同期でストリームに書き込みます。Asynchronously writes a character to the stream. |
WriteAsync(String) |
文字列をストリームに非同期で書き込みます。Asynchronously writes a string to the stream. |
WriteAsync(ReadOnlyMemory<Char>, CancellationToken) |
文字メモリ領域をストリームに非同期で書き込みます。Asynchronously writes a character memory region to the stream. |
WriteAsync(Char[], Int32, Int32) |
文字の部分配列をストリームに非同期で書き込みます。Asynchronously writes a subarray of characters to the stream. |
WriteAsync(Char)
文字を非同期でストリームに書き込みます。Asynchronously writes a character to the stream.
public:
override System::Threading::Tasks::Task ^ WriteAsync(char value);
public override System.Threading.Tasks.Task WriteAsync (char value);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (char value);
override this.WriteAsync : char -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : char -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As Char) As Task
パラメーター
- value
- Char
ストリームに書き込む文字。The character to write to the stream.
戻り値
非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.
- 属性
例外
ストリーム ライターは破棄されます。The stream writer is disposed.
ストリーム ライターは現在、前の書き込み操作で使用中です。The stream writer is currently in use by a previous write operation.
例
次の例では、メソッドを使用して、1文字 (文字 "a") をテキストファイルに書き込む方法を示し WriteAsync(Char) ます。The following example shows how to write a single character (the letter "a") to a text file by using the WriteAsync(Char) method.
using System;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
WriteCharacters();
}
static async void WriteCharacters()
{
using (StreamWriter writer = File.CreateText("newfile.txt"))
{
await writer.WriteAsync('a');
}
}
}
}
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
WriteCharacters()
End Sub
Async Sub WriteCharacters()
Dim oneLetter As Char = "a"
Using writer As StreamWriter = File.CreateText("newfile.txt")
Await writer.WriteAsync(oneLetter)
End Using
End Sub
End Module
適用対象
WriteAsync(String)
文字列をストリームに非同期で書き込みます。Asynchronously writes a string to the stream.
public:
override System::Threading::Tasks::Task ^ WriteAsync(System::String ^ value);
public override System.Threading.Tasks.Task WriteAsync (string value);
public override System.Threading.Tasks.Task WriteAsync (string? value);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (string value);
override this.WriteAsync : string -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : string -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As String) As Task
パラメーター
- value
- String
ストリームに書き込む文字列。The string to write to the stream. value
が null
の場合は、何も書き込まれません。If value
is null
, nothing is written.
戻り値
非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.
- 属性
例外
ストリーム ライターは破棄されます。The stream writer is disposed.
ストリーム ライターは現在、前の書き込み操作で使用中です。The stream writer is currently in use by a previous write operation.
例
次の例は、メソッドを使用してテキストファイルに文字列を書き込む方法を示して WriteAsync(String) います。The following example shows how to write a string to a text file by using the WriteAsync(String) method.
using System;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
WriteCharacters();
}
static async void WriteCharacters()
{
using (StreamWriter writer = File.CreateText("newfile.txt"))
{
await writer.WriteAsync("Example text as string");
}
}
}
}
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
WriteCharacters()
End Sub
Async Sub WriteCharacters()
Using writer As StreamWriter = File.CreateText("newfile.txt")
Await writer.WriteAsync("Example text as string")
End Using
End Sub
End Module
適用対象
WriteAsync(ReadOnlyMemory<Char>, CancellationToken)
文字メモリ領域をストリームに非同期で書き込みます。Asynchronously writes a character memory region to the stream.
public override System.Threading.Tasks.Task WriteAsync (ReadOnlyMemory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
override this.WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (buffer As ReadOnlyMemory(Of Char), Optional cancellationToken As CancellationToken = Nothing) As Task
パラメーター
- buffer
- ReadOnlyMemory<Char>
ストリームに書き込む文字メモリ領域。The character memory region to write to the stream.
- cancellationToken
- CancellationToken
キャンセル要求を監視するためのトークン。The token to monitor for cancellation requests. 既定値は None です。The default value is None.
戻り値
非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.
適用対象
WriteAsync(Char[], Int32, Int32)
文字の部分配列をストリームに非同期で書き込みます。Asynchronously writes a subarray of characters to the stream.
public:
override System::Threading::Tasks::Task ^ WriteAsync(cli::array <char> ^ buffer, int index, int count);
public override System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (buffer As Char(), index As Integer, count As Integer) As Task
パラメーター
- buffer
- Char[]
書き込むデータを格納する文字配列。A character array that contains the data to write.
- index
- Int32
データの読み取りを開始する、バッファー内の文字位置。The character position in the buffer at which to begin reading data.
- count
- Int32
書き込む文字の最大数。The maximum number of characters to write.
戻り値
非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.
- 属性
例外
buffer
が null
です。buffer
is null
.
index
に count
を加算した値がバッファーの長さを超えています。The index
plus count
is greater than the buffer length.
index
または count
が負の値です。index
or count
is negative.
ストリーム ライターは破棄されます。The stream writer is disposed.
ストリーム ライターは現在、前の書き込み操作で使用中です。The stream writer is currently in use by a previous write operation.
例
次の例は、メソッドを使用してテキストファイルに複数の文字を書き込む方法を示して WriteAsync(Char[], Int32, Int32) います。The following example shows how to write multiple characters to a text file by using the WriteAsync(Char[], Int32, Int32) method.
using System;
using System.Text;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
WriteCharacters();
}
static async void WriteCharacters()
{
UnicodeEncoding ue = new UnicodeEncoding();
char[] charsToAdd = ue.GetChars(ue.GetBytes("Example string"));
using (StreamWriter writer = File.CreateText("newfile.txt"))
{
await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length);
}
}
}
}
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
WriteCharacters()
End Sub
Async Sub WriteCharacters()
Dim ue As UnicodeEncoding = New UnicodeEncoding()
Dim charsToAdd() = ue.GetChars(ue.GetBytes("Example string"))
Using writer As StreamWriter = File.CreateText("newfile.txt")
Await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length)
End Using
End Sub
End Module