StringReader.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보다 큰 경우

문자열 판독기를 삭제했습니다.

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

예제

다음 예제에서는 문자열에서 한 번에 한 줄을 비동기적으로 읽는 방법을 보여 있습니다.

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            ReadCharacters();
        }

        static async void ReadCharacters()
        {
            StringBuilder stringToRead = new StringBuilder();
            stringToRead.AppendLine("Characters in 1st line to read");
            stringToRead.AppendLine("and 2nd line");
            stringToRead.AppendLine("and the end");

            string readText;

            using (StringReader reader = new StringReader(stringToRead.ToString()))
            {
                while ((readText = await reader.ReadLineAsync()) != null)
                {
                    Console.WriteLine(readText);
                }
            }
        }
    }
}
// The example displays the following output:
//
// Characters in 1st line to read
// and 2nd line
// and the end
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        ReadCharacters()
    End Sub

    Async Sub ReadCharacters()
        Dim stringToRead = New StringBuilder()
        stringToRead.AppendLine("Characters in 1st line to read")
        stringToRead.AppendLine("and 2nd line")
        stringToRead.AppendLine("and the end")

        Using reader As StringReader = New StringReader(stringToRead.ToString())
            Dim readText As String = Await reader.ReadLineAsync()
            While Not IsNothing(readText)
                Console.WriteLine(readText)
                readText = Await reader.ReadLineAsync()
            End While
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in 1st line to read
' and 2nd line
' and the end
'

설명

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

적용 대상