Export (0) Print
Expand All

HttpListener.IsListening Property

Gets a value that indicates whether HttpListener has been started.

Namespace: System.Net
Assembly: System (in system.dll)

public bool IsListening { get; }
/** @property */
public boolean get_IsListening ()

public function get IsListening () : boolean

Not applicable.

Property Value

true if the HttpListener was started; otherwise, false.

To start an HttpListener, call the Start method.

The following code example demonstrates using this property to determine the listening state of an instance.

public static void DisplayPrefixesAndState(HttpListener listener)
{
    // List the prefixes to which the server listens.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    if (prefixes.Count == 0)
    {
        Console.WriteLine("There are no prefixes.");
    }
    foreach(string prefix in prefixes)
    {
        Console.WriteLine(prefix);
    }
    // Show the listening state.
    if (listener.IsListening)
    {
        Console.WriteLine("The server is listening.");
    }
}

public static void DisplayPrefixesAndState(HttpListener listener)
{
    // List the prefixes to which the server listens.
    HttpListenerPrefixCollection prefixes = listener.get_Prefixes();
    if (prefixes.get_Count() == 0) {
        Console.WriteLine("There are no prefixes.");
    }

    IEnumerator objEnum = prefixes.GetEnumerator();
    String prefix;
    while (objEnum.MoveNext()) {
        prefix = objEnum.get_Current().ToString();
        Console.WriteLine(prefix);
    }
    // Show the listening state.
    if (listener.get_IsListening()) {
        Console.WriteLine("The server is listening.");
    }
} //DisplayPrefixesAndState

Windows 98, Windows Server 2003, Windows XP Media Center Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft