HttpListenerPrefixCollection.Clear Método

Definição

Remove todos os prefixos de URI (Uniform Resource Identifier) da coleção.

public:
 virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

Implementações

Exceções

Falha de uma chamada de função do Windows. Verifique a propriedade ErrorCode da exceção para determinar a causa da exceção.

O HttpListener associado a esta coleção está fechado.

Exemplos

O exemplo de código a seguir remove todos os prefixos em um HttpListenerPrefixCollection.

public static bool RemoveAllPrefixes(HttpListener listener)
{
    // Get the prefixes that the Web server is listening to.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    try
    {
        prefixes.Clear();
    }
    // If the operation failed, return false.
    catch
    {
        return false;
    }
    return true;
}
Public Shared Function RemoveAllPrefixes(ByVal listener As HttpListener) As Boolean
    ' Get the prefixes that the Web server is listening to.
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes

    Try
        prefixes.Clear()
    Catch ' If the operation failed, return false.
        Return False
    End Try

    Return True
End Function

Comentários

Depois de chamar esse método, você não poderá iniciar o associado HttpListener sem adicionar novos prefixos; se você tentar fazer isso, uma exceção será gerada.

Notas aos Chamadores

Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo. Para obter mais informações, consulte Rastreamento de rede no .NET Framework.

Aplica-se a

Confira também