Rediģēt

Kopīgot, izmantojot


File.ReadLinesAsync Method

Definition

Overloads

ReadLinesAsync(String, CancellationToken)

Asynchronously reads the lines of a file.

ReadLinesAsync(String, Encoding, CancellationToken)

Asynchronously reads the lines of a file that has a specified encoding.

ReadLinesAsync(String, CancellationToken)

Source:
File.cs
Source:
File.cs
Source:
File.cs

Asynchronously reads the lines of a file.

public static System.Collections.Generic.IAsyncEnumerable<string> ReadLinesAsync (string path, System.Threading.CancellationToken cancellationToken = default);
static member ReadLinesAsync : string * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<string>
Public Shared Function ReadLinesAsync (path As String, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of String)

Parameters

path
String

The file to read.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

The async enumerable that represents all the lines of the file, or the lines that are the result of a query.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

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 ReadLines(String).

Applies to

ReadLinesAsync(String, Encoding, CancellationToken)

Source:
File.cs
Source:
File.cs
Source:
File.cs

Asynchronously reads the lines of a file that has a specified encoding.

public static System.Collections.Generic.IAsyncEnumerable<string> ReadLinesAsync (string path, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default);
static member ReadLinesAsync : string * System.Text.Encoding * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<string>
Public Shared Function ReadLinesAsync (path As String, encoding As Encoding, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of String)

Parameters

path
String

The file to read.

encoding
Encoding

The encoding that is applied to the contents of the file.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

The async enumerable that represents all the lines of the file, or the lines that are the result of a query.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

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 ReadLines(String, Encoding).

Applies to