StreamReader.ReadToEndAsync Method ()
.NET Framework (current version)
Reads all characters from the current position to the end of the stream asynchronously and returns them as one string.
Assembly: mscorlib (in mscorlib.dll)
<ComVisibleAttribute(False)> <HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading := True)> Public Overrides Function ReadToEndAsync As Task(Of String)
Return Value
Type: System.Threading.Tasks.Task(Of String)A task that represents the asynchronous read operation. The value of the TResult parameter contains a string with the characters from the current position to the end of the stream.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The number of characters is larger than MaxValue. |
| ObjectDisposedException | The stream has been disposed. |
| InvalidOperationException | The reader is currently in use by a previous read operation. |
The following example shows how to read the contents of a file by using the ReadToEndAsync() method.
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
Universal Windows Platform
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Show: