StreamReader.ReadLineAsync 메서드

정의

오버로드

ReadLineAsync()

현재 스트림에서 한 줄의 문자를 비동기적으로 읽고 데이터를 문자열로 반환합니다.

ReadLineAsync(CancellationToken)

현재 스트림에서 한 줄의 문자를 비동기적으로 읽고 데이터를 문자열로 반환합니다.

ReadLineAsync()

Source:
StreamReader.cs
Source:
StreamReader.cs
Source:
StreamReader.cs

현재 스트림에서 한 줄의 문자를 비동기적으로 읽고 데이터를 문자열로 반환합니다.

public:
 override System::Threading::Tasks::Task<System::String ^> ^ ReadLineAsync();
public override System.Threading.Tasks.Task<string> ReadLineAsync ();
public override System.Threading.Tasks.Task<string?> ReadLineAsync ();
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task<string> ReadLineAsync ();
override this.ReadLineAsync : unit -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.ReadLineAsync : unit -> System.Threading.Tasks.Task<string>
Public Overrides Function ReadLineAsync () As Task(Of String)

반환

비동기 읽기 작업을 나타내는 작업입니다. TResult 매개 변수의 값은 스트림의 다음 줄을 포함하거나 모든 문자가 읽혀진 경우에는 null입니다.

특성

예외

다음 줄의 문자 수가 Int32.MaxValue보다 큽 있습니다.

스트림이 삭제되었습니다.

판독기가 현재 이전 읽기 작업에서 사용 중입니다.

예제

다음 예제에서는 메서드를 사용하여 파일의 첫 번째 줄을 읽는 ReadLineAsync() 방법을 보여줍니다.

using System;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        static async Task Main()
        {
            await ReadCharacters();
        }

        static async Task ReadCharacters()
        {
            String result;
            using (StreamReader reader = File.OpenText("existingfile.txt"))
            {
                Console.WriteLine("Opened file.");
                result = await reader.ReadLineAsync();
                Console.WriteLine("First line contains: " + result);
            }
        }
    }
}
Imports System.IO

Module Module1

    Sub Main()
        ReadCharacters()
    End Sub

    Async Sub ReadCharacters()
        Dim result As String

        Using reader As StreamReader = File.OpenText("existingfile.txt")
            Console.WriteLine("Opened file.")
            result = Await reader.ReadLineAsync()
            Console.WriteLine("First line contains: " + result)
        End Using
    End Sub
End Module

설명

이 메서드는 메서드의 동기 대응에서 throw할 수 있는 모든 비사용 예외를 반환하는 태스크에 저장됩니다. 예외가 반환된 작업에 저장되면 작업이 대기될 때 해당 예외가 throw됩니다. 와 같은 ArgumentException사용 예외는 여전히 동기적으로 throw됩니다. 저장된 예외는 에서 throw ReadLine()된 예외를 참조하세요.

적용 대상

ReadLineAsync(CancellationToken)

Source:
StreamReader.cs
Source:
StreamReader.cs
Source:
StreamReader.cs

현재 스트림에서 한 줄의 문자를 비동기적으로 읽고 데이터를 문자열로 반환합니다.

public:
 override System::Threading::Tasks::ValueTask<System::String ^> ReadLineAsync(System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.ValueTask<string?> ReadLineAsync (System.Threading.CancellationToken cancellationToken);
override this.ReadLineAsync : System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<string>
Public Overrides Function ReadLineAsync (cancellationToken As CancellationToken) As ValueTask(Of String)

매개 변수

cancellationToken
CancellationToken

취소 요청을 모니터링할 토큰입니다.

반환

비동기 읽기 작업을 나타내는 값 작업입니다. 매개 변수의 TResult 값은 스트림의 다음 줄을 포함하거나 모든 문자를 읽은 경우 입니다 null .

예외

다음 줄의 문자 수가 Int32.MaxValue보다 큽 있습니다.

스트림 판독기가 삭제되었습니다.

판독기가 현재 이전 읽기 작업에서 사용 중입니다.

취소 토큰이 취소되었습니다. 이 예외는 반환된 작업에 저장됩니다.

설명

이 메서드가 를 통해 cancellationToken취소된 경우 현재 Stream 에서 읽어왔지만 (에 의해 StreamReader) 저장되지 않았거나(호출자에게) 반환되지 않은 일부 데이터가 손실될 수 있습니다.

이 메서드는 메서드의 동기 대응에서 throw할 수 있는 모든 비사용 예외를 반환하는 태스크에 저장됩니다. 예외가 반환된 작업에 저장되면 작업이 대기될 때 해당 예외가 throw됩니다. 와 같은 ArgumentException사용 예외는 여전히 동기적으로 throw됩니다. 저장된 예외는 에서 throw ReadLine()된 예외를 참조하세요.

적용 대상