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

定義

關閉 HttpListenerShuts down the HttpListener.

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

範例

下列程式碼範例將示範如何Close呼叫方法: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

備註

呼叫這個方法之後, 您就無法再使用HttpListener物件。After calling this method, you can no longer use the HttpListener object. 若要暫時暫停HttpListener物件, 請Stop使用方法。To temporarily pause an HttpListener object, use the Stop method.

這個方法會關閉物件HttpListener , 而不處理已排入佇列的要求。This method shut downs the HttpListener object without processing queued requests. 所有暫止的要求都無法完成。Any pending requests are unable to complete.

給呼叫者的注意事項

在應用程式中啟用網路追蹤時,這個成員會輸出追蹤資訊。This member outputs trace information when you enable network tracing in your application. 如需詳細資訊, 請參閱.NET Framework 中的網路追蹤For more information, see Network Tracing in the .NET Framework.

適用於