HttpListener.Close HttpListener.Close HttpListener.Close HttpListener.Close Method

Définition

Arrête le HttpListener.Shuts down the HttpListener.

public:
 void Close();
public void Close ();
member this.Close : unit -> unit
Public Sub Close ()

Exemples

L’exemple de code suivant montre l’appel la Close méthode :The following code example demonstrates calling the Close method:


public static void NonblockingListener(string [] prefixes)
{
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback),listener);
    // Applications can do some work here while waiting for the 
    // request. If no work can be done until you have processed a request,
    // use a wait handle to prevent this thread from terminating
    // while the asynchronous operation completes.
    Console.WriteLine("Waiting for request to be processed asyncronously.");
    result.AsyncWaitHandle.WaitOne();
    Console.WriteLine("Request processed asyncronously.");
    listener.Close();
}
Public Shared Sub NonblockingListener(ByVal prefixes As String())
    Dim listener As HttpListener = New HttpListener()

    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next

    listener.Start()
    Dim result As IAsyncResult = listener.BeginGetContext(New AsyncCallback(AddressOf ListenerCallback), listener)
    ' Applications can do some work here while waiting for the 
    ' request. If no work can be done until you have processed a request,
    ' use a wait handle to prevent this thread from terminating
    ' while the asynchronous operation completes.
    Console.WriteLine("Waiting for request to be processed asyncronously.")
    result.AsyncWaitHandle.WaitOne()
    Console.WriteLine("Request processed asyncronously.")
    listener.Close()
End Sub

Remarques

Après avoir appelé cette méthode, vous ne pouvez plus utiliser le HttpListener objet.After calling this method, you can no longer use the HttpListener object. Pour interrompre temporairement une HttpListener de l’objet, utilisez le Stop (méthode).To temporarily pause an HttpListener object, use the Stop method.

Cette méthode ferme downs le HttpListener objet sans traiter les demandes en file d’attente.This method shut downs the HttpListener object without processing queued requests. Toutes les demandes en attente ne peuvent pas suivre.Any pending requests are unable to complete.

Notes pour les appelants

Ce membre génère des informations de traçage lorsque vous activez le traçage réseau dans votre application.This member outputs trace information when you enable network tracing in your application. Pour plus d’informations, consultez le traçage réseau dans le .NET Framework.For more information, see Network Tracing in the .NET Framework.

S’applique à