HttpListener.IsListening 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,表示是否已啟動 HttpListener。
public:
property bool IsListening { bool get(); };
public bool IsListening { get; }
member this.IsListening : bool
Public ReadOnly Property IsListening As Boolean
屬性值
如果已啟動 HttpListener,則為 true
;否則為 false
。
範例
下列程式代碼範例示範如何使用這個屬性來判斷實例的接聽狀態。
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 Shared Sub DisplayPrefixesAndState(ByVal listener As HttpListener)
' List the prefixes to which the server listens.
Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes
If prefixes.Count = 0 Then
Console.WriteLine("There are no prefixes.")
End If
For Each prefix As String In prefixes
Console.WriteLine(prefix)
Next
' Show the listening state.
If listener.IsListening Then
Console.WriteLine("The server is listening.")
End If
End Sub
備註
若要啟動 HttpListener,請呼叫 Start 方法。