StreamReader.ReadLineAsync 메서드

정의

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

public:
 override System::Threading::Tasks::Task<System::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같은 사용 예외는 여전히 동기적으로 던져집니다. 저장된 예외는 .에 의해 ReadLine()throw된 예외를 참조하세요.

적용 대상