StreamReader.ReadLineAsync StreamReader.ReadLineAsync StreamReader.ReadLineAsync StreamReader.ReadLineAsync Method


Reads a line of characters asynchronously from the current stream and returns the data as a string.

 override System::Threading::Tasks::Task<System::String ^> ^ ReadLineAsync();
public override System.Threading.Tasks.Task<string> ReadLineAsync ();
override this.ReadLineAsync : unit -> System.Threading.Tasks.Task<string>
Public Overrides Function ReadLineAsync () As Task(Of String)


A task that represents the asynchronous read operation. The value of the TResult parameter contains the next line from the stream, or is null if all the characters have been read.



The following example shows how to read the first line of a file by using the ReadLineAsync() method.

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()
    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

Applies to