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 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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft