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 Value

Type: System.Boolean

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.");
    }
}

.NET Framework
Available since 2.0
Return to top
Show: