StringReader.ReadToEndAsync Metodo

Definizione

Overload

ReadToEndAsync()

Legge in modo asincrono tutti i caratteri dalla posizione corrente fino alla fine della stringa e li restituisce come singola stringa.

ReadToEndAsync(CancellationToken)

Legge in modo asincrono tutti i caratteri dalla posizione corrente fino alla fine della stringa e li restituisce come singola stringa.

ReadToEndAsync()

Source:
StringReader.cs
Source:
StringReader.cs
Source:
StringReader.cs

Legge in modo asincrono tutti i caratteri dalla posizione corrente fino alla fine della stringa e li restituisce come singola stringa.

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)

Restituisce

Attività che rappresenta l'operazione di lettura asincrona. Il valore del parametro TResult contiene una stringa con i caratteri compresi tra la posizione corrente e l'estremità della stringa.

Attributi

Eccezioni

Il numero di caratteri è maggiore di Int32.MaxValue.

Il lettore della stringa è stato eliminato.

Il lettore è attualmente usato da un'operazione di lettura precedente.

Esempio

Nell'esempio seguente viene illustrato come leggere un'intera stringa in modo asincrono.

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            ReadCharacters();
        }

        static async void ReadCharacters()
        {
            StringBuilder stringToRead = new StringBuilder();
            stringToRead.AppendLine("Characters in 1st line to read");
            stringToRead.AppendLine("and 2nd line");
            stringToRead.AppendLine("and the end");

            using (StringReader reader = new StringReader(stringToRead.ToString()))
            {
                string readText = await reader.ReadToEndAsync();
                Console.WriteLine(readText);
            }
        }
    }
}
// The example displays the following output:
//
// Characters in 1st line to read
// and 2nd line
// and the end
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        ReadCharacters()
    End Sub

    Async Sub ReadCharacters()
        Dim stringToRead = New StringBuilder()
        stringToRead.AppendLine("Characters in 1st line to read")
        stringToRead.AppendLine("and 2nd line")
        stringToRead.AppendLine("and the end")

        Using reader As StringReader = New StringReader(stringToRead.ToString())
            Dim readText As String = Await reader.ReadToEndAsync()
            Console.WriteLine(readText)
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in 1st line to read
' and 2nd line
' and the end
'

Commenti

Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da ReadToEnd().

Si applica a

ReadToEndAsync(CancellationToken)

Source:
StringReader.cs
Source:
StringReader.cs
Source:
StringReader.cs

Legge in modo asincrono tutti i caratteri dalla posizione corrente fino alla fine della stringa e li restituisce come singola stringa.

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)

Parametri

cancellationToken
CancellationToken

Token da monitorare per le richieste di annullamento.

Restituisce

Attività che rappresenta l'operazione di lettura asincrona. Il valore del parametro TResult contiene una stringa con i caratteri compresi tra la posizione corrente e l'estremità della stringa.

Eccezioni

Il numero di caratteri è maggiore di Int32.MaxValue.

Il lettore della stringa è stato eliminato.

Il lettore è attualmente usato da un'operazione di lettura precedente.

Il token di annullamento è stato annullato. Questa eccezione viene archiviata nell'attività restituita.

Commenti

Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da ReadToEnd().

Si applica a