HttpListener.Abort 方法

定义

立刻关闭 HttpListener 对象,这样会放弃所有当前排队的请求。

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

示例

下面的代码示例演示如何调用此方法。

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

注解

此方法释放此侦听器持有的所有资源。 任何挂起的请求都无法完成。

调用此方法后,如果尝试使用此 HttpListener,将收到 ObjectDisposedException

调用方说明

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。 有关详细信息,请参阅.NET Framework中的网络跟踪

适用于