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.

适用于