0
Answer

adding a project and accesing the form.. or network bandwidth monitr

Ask a question
Ajo Mathew

Ajo Mathew

14y
2.2k
1
I am doing a windows form where i need to get the network usage the upload,download details... seperatly from all the network adapters...
I already got the code but it was difficult to understand... FreeMeter from sourceforgenet...

where i need only the upload and download detail showing function which is very depend on the other froms in the project...
this is the basic code
i have from another project...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace loopback
{
    class Program
    {
        static void Main(string[] args)
        {
            ShowNetworkTraffic();
        }
        private static void ShowNetworkTraffic()
        {
            PerformanceCounterCategory performanceCounterCategory = new PerformanceCounterCategory("Network Interface");
            string instance = performanceCounterCategory.GetInstanceNames()[2]; // 1st NIC !
            PerformanceCounter performanceCounterSent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance);
            PerformanceCounter performanceCounterReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance);
            float up =0, dwn = 0;
            for (int i = 0; i < 150; i++)
            {
                up = up + performanceCounterSent.NextValue();
                dwn = dwn + performanceCounterReceived.NextValue();
                Console.WriteLine("bytes sent: {0}k\tbytes received: {1}k", performanceCounterSent.NextValue(), performanceCounterReceived.NextValue());
                Thread.Sleep(100);
            }
            Console.WriteLine("{0}", up);
            Console.ReadKey();
        }
    }
}