HttpListenerPrefixCollection.Clear メソッド

定義

コレクションからすべての URI プレフィックスを削除します。

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

実装

例外

Windows の関数呼び出しが失敗しました。 例外の ErrorCode プロパティを調べて、例外の原因を確認します。

このコレクションに関連付けられている HttpListener は閉じています。

次のコード例では、 内のすべてのプレフィックスを 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

注釈

このメソッドを呼び出した後は、新しいプレフィックスを追加せずに関連付けられた HttpListener を開始することはできません。これを行おうとすると、例外がスローされます。

注意 (呼び出し元)

このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「.NET Frameworkのネットワーク トレース」を参照してください。

適用対象

こちらもご覧ください