StringWriter.WriteAsync Méthode

Définition

Écrit des données dans la chaîne de façon asynchrone.

Surcharges

WriteAsync(Char)

Écrit un caractère dans la chaîne de façon asynchrone.

WriteAsync(String)

Écrit une chaîne dans la chaîne actuelle de façon asynchrone.

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

Écrit de façon asynchrone une zone de mémoire de caractères dans la chaîne.

WriteAsync(StringBuilder, CancellationToken)

Écrit de façon asynchrone la représentation sous forme de texte d’un générateur de chaîne dans la chaîne.

WriteAsync(Char[], Int32, Int32)

Écrit un sous-tableau de caractères dans la chaîne de façon asynchrone.

WriteAsync(Char)

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

Écrit un caractère dans la chaîne de façon asynchrone.

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

Paramètres

value
Char

Caractère à écrire dans la chaîne.

Retours

Tâche qui représente l’opération d’écriture asynchrone.

Attributs

Exceptions

Le writer de chaîne est supprimé.

Le writer de chaîne est actuellement utilisé par une opération d’écriture précédente.

Exemples

L’exemple suivant montre comment écrire des caractères à l’aide de la WriteAsync(Char) méthode .

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
'

Remarques

Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par Write(Char).

S’applique à

WriteAsync(String)

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

Écrit une chaîne dans la chaîne actuelle de façon asynchrone.

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

Paramètres

value
String

Chaîne à écrire. Si value a la valeur null, rien n'est écrit dans le flux de texte.

Retours

Tâche qui représente l’opération d’écriture asynchrone.

Attributs

Exceptions

Le writer de chaîne est supprimé.

Le writer de chaîne est actuellement utilisé par une opération d’écriture précédente.

Exemples

L’exemple suivant montre comment écrire une chaîne à l’aide de la WriteAsync(String) méthode .

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
'

Remarques

Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par Write(String).

S’applique à

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

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

Écrit de façon asynchrone une zone de mémoire de caractères dans la chaîne.

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

Paramètres

buffer
ReadOnlyMemory<Char>

Zone de mémoire de caractères à écrire dans la chaîne.

cancellationToken
CancellationToken

Jeton pour surveiller les requêtes d'annulation. La valeur par défaut est None.

Retours

Tâche qui représente l’opération d’écriture asynchrone.

Exceptions

Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.

S’applique à

WriteAsync(StringBuilder, CancellationToken)

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

Écrit de façon asynchrone la représentation sous forme de texte d’un générateur de chaîne dans la chaîne.

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

Paramètres

value
StringBuilder

Générateur de chaînes à écrire dans la chaîne.

cancellationToken
CancellationToken

Jeton pour surveiller les requêtes d'annulation. La valeur par défaut est None.

Retours

Tâche qui représente l’opération d’écriture asynchrone.

Exceptions

Le jeton d’annulation a été annulé. Cette exception est stockée dans la tâche retournée.

Remarques

Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par Write(StringBuilder).

S’applique à

WriteAsync(Char[], Int32, Int32)

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

Écrit un sous-tableau de caractères dans la chaîne de façon asynchrone.

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

Paramètres

buffer
Char[]

Tableau de caractères à partir duquel les données doivent être écrites.

index
Int32

Position dans la mémoire tampon où démarrer la lecture des données.

count
Int32

Nombre maximal de caractères à écrire.

Retours

Tâche qui représente l’opération d’écriture asynchrone.

Attributs

Exceptions

buffer a la valeur null.

index plus count est supérieur à la longueur de la mémoire tampon.

index ou count est un nombre négatif.

Le writer de chaîne est supprimé.

Le writer de chaîne est actuellement utilisé par une opération d’écriture précédente.

Exemples

L’exemple suivant montre comment écrire des caractères à l’aide de la WriteAsync(Char[], Int32, Int32) méthode .

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
'

Remarques

Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par Write(Char[], Int32, Int32).

S’applique à