StreamReader.ReadToEndAsync Metoda

Definice

Přečte všechny znaky z aktuální pozice na konec proudu asynchronně a vrátí je jako jeden řetězec.Reads all characters from the current position to the end of the stream asynchronously and returns them as one string.

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

Návraty

Task<String>

Úkol reprezentující operaci asynchronního čtení.A task that represents the asynchronous read operation. Hodnota TResult parametru obsahuje řetězec se znaky z aktuální pozice až na konec proudu.The value of the TResult parameter contains a string with the characters from the current position to the end of the stream.

Atributy

Výjimky

Počet znaků je větší než MaxValue .The number of characters is larger than MaxValue.

Datový proud byl vyřazen.The stream has been disposed.

Čtecí modul aktuálně používá předchozí operace čtení.The reader is currently in use by a previous read operation.

Příklady

Následující příklad ukazuje, jak číst obsah souboru pomocí ReadToEndAsync() metody.The following example shows how to read the contents of a file by using the ReadToEndAsync() 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.ReadToEndAsync();
                Console.WriteLine("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.ReadToEndAsync()
            Console.WriteLine("Contains: " + result)
        End Using
    End Sub
End Module

Platí pro