Hello.
I am developing an application and i needed for find if a certain IP:Port is online or not and keep updating it. At the moment i have it pinging the IP:Port every time a timer ticks, this works fine but every time it ticks, the application window freezes for a few seconds, which i don't want.
This is the code i have atm:
Imports System.Net
Imports System.Net.Sockets
Public Class MSSUI
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
Dim bBtnClicked As Boolean = False
Private Sub IPbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IPbox.TextChanged
End Sub
Private Sub MSSUI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
IPbox.Text = h.AddressList.GetValue(0).ToString + ":27015"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If bBtnClicked = True Then
Dim tcpClient As New TcpClient
Dim IP As String = h.AddressList.GetValue(0).ToString
Dim Port As Int32 = portbox.Text
Dim IPAddress As IPAddress = IPAddress.Parse(IP)
Try
tcpClient.Connect(IP, Port)
status1.Text = "Server Online"
Catch err As Exception
status1.Text = "No Server Online"
End Try
Else
status1.Text = "No Server Online"
End If
bBtnClicked = True
End Sub
End Class
(The +27015 on *h.AddressList.GetValue(0).ToString + ":27015"* is just to test the port)
Is there a better way to do it than this? all i want to do is find if the IP:Port is online or not and refresh the status. (with out having the application freeze)