HttpListener.Abort 方法

定義

立即關閉 HttpListener 物件,並捨棄所有目前排入佇列的要求。Shuts down the HttpListener object immediately, discarding all currently queued requests.

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

範例

下列程式碼範例將示範如何呼叫這個方法。The following code example demonstrates calling this method.

public static void CheckTestUrl(HttpListener listener, HttpListenerRequest request)
{
    if (request.RawUrl == "/www.contoso.com/test/NoReply")
    {
        listener.Abort ();
        return;
    }

}
Public Shared Sub CheckTestUrl(ByVal listener As HttpListener, ByVal request As HttpListenerRequest)
    If request.RawUrl = "/www.contoso.com/test/NoReply" Then
        listener.Abort()
        Return
    End If
End Sub

備註

這個方法會處置此接聽項所持有的所有資源。This method disposes of all resources held by this listener. 所有暫止的要求都無法完成。Any pending requests are unable to complete.

呼叫此方法之後,如果您嘗試使用此 HttpListener,將會收到 ObjectDisposedExceptionAfter calling this method, you will receive an ObjectDisposedException if you attempt to use this HttpListener.

給呼叫者的注意事項

在應用程式中啟用網路追蹤時,這個成員會輸出追蹤資訊。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.

適用於