StringReader.ReadLineAsync 메서드

정의

오버로드

ReadLineAsync()

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

ReadLineAsync(CancellationToken)

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

ReadLineAsync()

Source:
StringReader.cs
Source:
StringReader.cs
Source:
StringReader.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보다 큽 있습니다.

문자열 판독기가 삭제된 경우

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

예제

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

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사용 예외는 여전히 동기적으로 throw됩니다. 저장된 예외는 에서 throw ReadLine()된 예외를 참조하세요.

적용 대상

ReadLineAsync(CancellationToken)

Source:
StringReader.cs
Source:
StringReader.cs
Source:
StringReader.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보다 큽 있습니다.

문자열 판독기가 삭제된 경우

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

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

설명

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

적용 대상