Reads all characters from the current position to the end of the stream asynchronously and returns them as one string.
ReadToEndAsync(CancellationToken)Reads all characters from the current position to the end of the stream asynchronously and returns them as one string.
ReadToEndAsync()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)
Returns
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.
The stream has been disposed.
The reader is currently in use by a previous read operation.
ExamplesThe 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
Remarks
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ReadToEnd().
ReadToEndAsync(CancellationToken)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(System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<string> ReadToEndAsync(System.Threading.CancellationToken cancellationToken);
override this.ReadToEndAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<string>
Public Overrides Function ReadToEndAsync (cancellationToken As CancellationToken) As Task(Of String)
Parameters Returns
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.
The stream reader has been disposed.
The reader is currently in use by a previous read operation.
The cancellation token was canceled. This exception is stored into the returned task.
RemarksIf this method is canceled via cancellationToken
, some data that has been read from the current Stream but not stored (by the StreamReader) or returned (to the caller) may be lost.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ReadToEnd().
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4