I am working on a Bandwidth monitoring system, i want it loop, displaying the amount of data being sent or received at a given instance, but the problem is that the system freezes when its processing, i just want it to work in background, displaying the results in the text boxes as defined in the system whilst i am doing other things. Here is the function:
Private Function netSpeed() As Boolean
Dim networkInterfaces As New System.Diagnostics.PerformanceCounterCategory("Network Interface")
Dim nics As String() = networkInterfaces.GetInstanceNames()
Dim bytesSent(nics.Length - 1) As System.Diagnostics.PerformanceCounter
Dim bytesReceived(nics.Length - 1) As System.Diagnostics.PerformanceCounter
bytesSent(9) = New System.Diagnostics.PerformanceCounter("Network Interface", "Bytes Sent/sec", nics(9), True)
bytesReceived(9) = New System.Diagnostics.PerformanceCounter("Network Interface", "Bytes received/sec", nics(9), True)
Dim up As Integer
Dim down As Integer
For k As Integer = 0 To 2
up = bytesSent(9).NextValue
down = bytesReceived(9).NextValue
System.Threading.Thread.Sleep(1000)
Next
TextBox1.Text = up
TextBox2.Text = down
Return True
End Function
Please note: I am testing interface 9. i.e Ethernet interface. I appreciate suggestions