我正在开发带宽监控系统,我希望它循环显示在给定实例中发送或接收的数据量,但问题是系统在处理时冻结,我只想让它在后台工作,显示当我在做其他事情时,系统中定义的文本框中的结果。这是功能:
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
请注意:我正在测试接口 9。即以太网接口。我很欣赏建议