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

定義

HttpListener を終了します。Shuts 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.

適用対象