Lire en anglais

Partager via


SslStream.EndWrite(IAsyncResult) Méthode

Définition

Termine une opération d'écriture asynchrone démarrée avec un appel précédent à BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).

public override void EndWrite(IAsyncResult asyncResult);

Paramètres

asyncResult
IAsyncResult

Instance de IAsyncResult retournée par un appel à BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).

Exceptions

asyncResult a la valeur null.

asyncResult n'a pas été créé par un appel à la méthode BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).

Aucune opération d'écriture n'est en attente d'achèvement.

- ou -

L'authentification n'a pas été effectuée.

L'opération d'écriture a échoué.

Exemples

L’exemple de code suivant illustre la fin d’une opération d’écriture asynchrone.

void WriteCallback(IAsyncResult ar)
{
    ClientState state = (ClientState) ar.AsyncState;
    SslStream stream = state.stream;
    try
    {
        Console.WriteLine("Writing data to the client.");
        stream.EndWrite(ar);
    }
    catch (Exception writeException)
    {
        Console.WriteLine("Write error: {0}",
            writeException.Message);
        state.Close();
        return;
    }
    Console.WriteLine("Finished with client.");
    state.Close();
}

Remarques

Si l’opération n’est pas terminée, cette méthode se bloque jusqu’à ce qu’elle le fasse.

Une application ne peut pas appeler cette méthode tant que vous n’avez pas réussi à vous authentifier. Pour vous authentifier, appelez l’une AuthenticateAsClientdes méthodes , ou BeginAuthenticateAsClient, AuthenticateAsServer. BeginAuthenticateAsServer

Pour effectuer cette opération de manière synchrone, utilisez la Write méthode .

S’applique à

Produit Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1