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.

반환

Task

비동기 쓰기 작업을 나타내는 작업입니다.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.

예제

다음 예제에서는 메서드를 사용 하 여 단일 문자 (문자 "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. valuenull이면 아무 것도 쓰지 않습니다.If value is null, nothing is written.

반환

Task

비동기 쓰기 작업을 나타내는 작업입니다.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);
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.

반환

Task

비동기 쓰기 작업을 나타내는 작업입니다.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.

반환

Task

비동기 쓰기 작업을 나타내는 작업입니다.A task that represents the asynchronous write operation.

특성

예외

buffer이(가) null인 경우buffer is null.

indexcount의 합이 버퍼 길이보다 큽니다.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

적용 대상