1
我想檢查我的服務器(本地服務器)是啓動還是關閉。 我想通過我的服務器名:myDEVServer12(http://www.example.com/ss.asp)WebRequest來檢查服務器
Public Function CheckServer(ByVal ServerName As String) As Boolean
Try
Dim request As WebRequest = WebRequest.Create(ServerName)
Dim response As WebResponse = request.GetResponse()
imgServer1.ImageUrl = ("~/Images/green_light.png")
Catch ex As Exception
imgServer1.ImageUrl = ("~/Images/red_light.png")
Return False
End Try
Return True
End Function
我也嘗試過使用Ping。它的工作原理,但網頁需要很長的時間來加載(4臺服務器)
Dim ping As New Ping
Try
Dim pingreply = ping.Send(lblServer1.Text, 2000)
If pingreply.Status = IPStatus.Success Then
imgServer1.ImageUrl = ("~/Images/green_light.png")
Else
imgServer1.ImageUrl = ("~/Images/red_light.png")
End If
Catch ex As Exception
imgServer1.ImageUrl = ("~/Images/red_light.png")
End Try
什麼是你的問題? – TheCodeKing
減少ping方法的超時時間,200應該足夠了。對於多臺服務器,您也可以將請求線程化以加快完成時間。 – Kratz