2013-04-26 2 views
1

평균 속도를 얻기 위해 인터넷 연결의 트래픽, 즉 특정 시간의 평균 속도를 모니터링하려고합니다. 이 코드를 시도했지만 작동하지 않습니다. 내가 어디로 잘못 가고 있니?대역폭 모니터링 시스템

Function bwmonitor() 
    Dim pc As New PerformanceCounterCategory("Network Interface") 
    Dim instance As String = pc.GetInstanceNames(0) 
    Dim bs As New PerformanceCounter("Network Interface", "Bytes Sent/sec", instance) 
    Dim br As New PerformanceCounter("Network Interface", "Bytes Received/Sec", instance) 
    Dim k As Integer = 0 

    Do 
     k = k + 1 
     Dim kbsent As Integer = bs.NextValue()/1024 
     Dim kbRecieved As Integer = br.NextValue/1024 
     TextBox10.Text = kbsent 
     TextBox11.Text = kbRecieved 
     Threading.Thread.Sleep(1000) 
    Loop Until k = 10 

    Return 0 
End Function 

나는 함수를 호출했지만 텍스트 상자는 0 만 반환합니다.

답변

1

사용중인 네트워크 인터페이스를 찾으려면 아래 코드로 콘솔 응용 프로그램을 만들고 어떤 인터페이스가 활성화되어 있는지 확인해야합니다.

또한 그런 방식으로 UI를 업데이트 할 수 없으므로 배경 작업자를 사용하여 텍스트 상자에 롤링 업데이트가 필요합니다.

Sub Main() 

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 
    Dim i As Integer 
    For i = 0 To nics.Length - 1 
    bytesSent(i) = New System.Diagnostics.PerformanceCounter("Network Interface", "Bytes Sent/sec", nics(i), True) 
    bytesReceived(i) = New System.Diagnostics.PerformanceCounter("Network Interface", "Bytes received/sec", nics(i), True) 
Next 
    'Dim ni As System.Diagnostics.PerformanceCounter 
For i = 0 To nics.Length - 1 
    System.Console.WriteLine(String.Format("  interface {0}: {1} ", i, nics(i))) 
Next 
Do 
     For i = 0 To nics.Length - 1 
      System.Console.WriteLine(String.Format("  interface {0}: {1} bytes sent/sec, {2} bytes received/sec. ", i, bytesSent(i).NextValue, bytesReceived(i).NextValue)) 
     Next 

     System.Console.WriteLine("") 
     System.Console.WriteLine("") 
     System.Threading.Thread.Sleep(3000) 
Loop 

End Sub 
+0

thanx, 나는 여전히 도전하고있다. 나는 여전히 내 WindowsApplication과 통합하려고한다. 뭔가를 보내거나받는 평균 대역폭을 표시하는 데 도움이됩니다 변수에 할당 좋아해. –

+0

또한 인터페이스 9를 사용 중입니다 –

+0

GUI 부분을 해결했습니다 [Windows 콘솔 대역폭 모니터] (http://stackoverflow.com/questions/16264927/windows-console-bandwidth-monitoring-system) –

관련 문제