HttpListener.Close Metoda

Definice

Vypne .HttpListener

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

Příklady

Následující příklad kódu ukazuje volání Close metody:


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

Poznámky

Po volání této metody již nelze objekt používat HttpListener . Pokud chcete objekt dočasně pozastavit HttpListener , použijte metodu Stop .

Tato metoda vypne HttpListener objekt bez zpracování požadavků ve frontě. Všechny nevyřízené žádosti se nedají dokončit.

Poznámky pro volající

Tento člen poskytuje trasovací informace, když je ve vaší aplikaci povoleno trasování sítě. Další informace najdete v tématu Trasování sítě v rozhraní .NET Framework.

Platí pro