StringWriter.WriteAsync Metodo

Definizione

Scrive i dati nella stringa in modo asincrono.

Overload

WriteAsync(Char)

Scrive un carattere nella stringa in modo asincrono.

WriteAsync(String)

Scrive una stringa nella stringa corrente in modo asincrono.

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

Scrive in modo asincrono un'area di memoria di caratteri nella stringa.

WriteAsync(StringBuilder, CancellationToken)

Scrive in modo asincrono nella stringa la rappresentazione testuale di un generatore di stringhe.

WriteAsync(Char[], Int32, Int32)

Scrive una sottomatrice di caratteri nella stringa in modo asincrono.

WriteAsync(Char)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Scrive un carattere nella stringa in modo asincrono.

public:
 override System::Threading::Tasks::Task ^ WriteAsync(char value);
public override System.Threading.Tasks.Task WriteAsync (char value);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (char value);
override this.WriteAsync : char -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : char -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As Char) As Task

Parametri

value
Char

Carattere da scrivere nella stringa.

Restituisce

Attività che rappresenta l'operazione di scrittura asincrona.

Attributi

Eccezioni

Il writer di stringa viene eliminato.

Il writer di stringa è attualmente usato da un'operazione di scrittura precedente.

Esempio

Nell'esempio seguente viene illustrato come scrivere caratteri usando il WriteAsync(Char) metodo .

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

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

        static async void WriteCharacters()
        {
            StringBuilder stringToWrite = new StringBuilder("Characters in StringBuilder");
            stringToWrite.AppendLine();

            using (StringWriter writer = new StringWriter(stringToWrite))
            {
                UnicodeEncoding ue = new UnicodeEncoding();
                char[] charsToAdd = ue.GetChars(ue.GetBytes("and chars to add"));
                foreach (char c in charsToAdd)
                {
                    await writer.WriteAsync(c);
                }
                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// and chars to add
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim stringToWrite As StringBuilder = New StringBuilder("Characters in StringBuilder")
        stringToWrite.AppendLine()

        Using writer As StringWriter = New StringWriter(stringToWrite)

            Dim ue As UnicodeEncoding = New UnicodeEncoding()
            Dim charsToAdd() = ue.GetChars(ue.GetBytes("and chars to add"))
            For Each c As Char In charsToAdd
                Await writer.WriteAsync(c)
            Next
            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' and chars to add
'

Commenti

Questo metodo archivia nell'attività 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 Write(Char).

Si applica a

WriteAsync(String)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Scrive una stringa nella stringa corrente in modo asincrono.

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

Parametri

value
String

Stringa da scrivere. Se value è null, nel flusso di testo non viene scritto alcun dato.

Restituisce

Attività che rappresenta l'operazione di scrittura asincrona.

Attributi

Eccezioni

Il writer di stringa viene eliminato.

Il writer di stringa è attualmente usato da un'operazione di scrittura precedente.

Esempio

Nell'esempio seguente viene illustrato come scrivere una stringa usando il WriteAsync(String) metodo .

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

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

        static async void WriteCharacters()
        {
            StringBuilder stringToWrite = new StringBuilder("Characters in StringBuilder");
            stringToWrite.AppendLine();

            using (StringWriter writer = new StringWriter(stringToWrite))
            {
                await writer.WriteAsync("and add characters through StringWriter");
                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// and add characters through StringWriter
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim stringToWrite As StringBuilder = New StringBuilder("Characters in StringBuilder")
        stringToWrite.AppendLine()

        Using writer As StringWriter = New StringWriter(stringToWrite)
            Await writer.WriteAsync("and add characters through StringWriter")
            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' and add characters through StringWriter
'

Commenti

Questo metodo archivia nell'attività 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 Write(String).

Si applica a

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Scrive in modo asincrono un'area di memoria di caratteri nella stringa.

public override System.Threading.Tasks.Task WriteAsync (ReadOnlyMemory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
override this.WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (buffer As ReadOnlyMemory(Of Char), Optional cancellationToken As CancellationToken = Nothing) As Task

Parametri

buffer
ReadOnlyMemory<Char>

Area di memoria dei caratteri da scrivere nella stringa.

cancellationToken
CancellationToken

Token da monitorare per le richieste di annullamento. Il valore predefinito è None.

Restituisce

Attività che rappresenta l'operazione di scrittura asincrona.

Eccezioni

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

Si applica a

WriteAsync(StringBuilder, CancellationToken)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Scrive in modo asincrono nella stringa la rappresentazione testuale di un generatore di stringhe.

public override System.Threading.Tasks.Task WriteAsync (System.Text.StringBuilder? value, System.Threading.CancellationToken cancellationToken = default);
override this.WriteAsync : System.Text.StringBuilder * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As StringBuilder, Optional cancellationToken As CancellationToken = Nothing) As Task

Parametri

value
StringBuilder

Generatore di stringhe da scrivere nella stringa.

cancellationToken
CancellationToken

Token da monitorare per le richieste di annullamento. Il valore predefinito è None.

Restituisce

Attività che rappresenta l'operazione di scrittura asincrona.

Eccezioni

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

Commenti

Questo metodo archivia nell'attività 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 Write(StringBuilder).

Si applica a

WriteAsync(Char[], Int32, Int32)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Scrive una sottomatrice di caratteri nella stringa in modo asincrono.

public:
 override System::Threading::Tasks::Task ^ WriteAsync(cli::array <char> ^ buffer, int index, int count);
public override System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (buffer As Char(), index As Integer, count As Integer) As Task

Parametri

buffer
Char[]

Matrice di caratteri da cui scrivere i dati.

index
Int32

Posizione del carattere nel buffer da cui iniziare la lettura dei dati.

count
Int32

Numero massimo di caratteri da scrivere.

Restituisce

Attività che rappresenta l'operazione di scrittura asincrona.

Attributi

Eccezioni

buffer è null.

La somma di index e count è maggiore della lunghezza del buffer.

index o count è negativo.

Il writer di stringa viene eliminato.

Il writer di stringa è attualmente usato da un'operazione di scrittura precedente.

Esempio

Nell'esempio seguente viene illustrato come scrivere caratteri usando il WriteAsync(Char[], Int32, Int32) metodo .

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

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

        static async void WriteCharacters()
        {
            StringBuilder stringToWrite = new StringBuilder("Characters in StringBuilder");
            stringToWrite.AppendLine();

            using (StringWriter writer = new StringWriter(stringToWrite))
            {
                UnicodeEncoding ue = new UnicodeEncoding();
                char[] charsToAdd = ue.GetChars(ue.GetBytes("and chars to add"));

                await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length);

                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// and chars to add
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim stringToWrite As StringBuilder = New StringBuilder("Characters in StringBuilder")
        stringToWrite.AppendLine()

        Using writer As StringWriter = New StringWriter(stringToWrite)

            Dim ue As UnicodeEncoding = New UnicodeEncoding()
            Dim charsToAdd() = ue.GetChars(ue.GetBytes("and chars to add"))

            Await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length)

            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' and chars to add
'

Commenti

Questo metodo archivia nell'attività 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 Write(Char[], Int32, Int32).

Si applica a