Search code examples
c#mathnetwork-programmingwmi

Getting network utilization using wmi in c#


I am trying to get a percentage value for network utilization based on per adapter

I've tried this:

CurrentBandwidth = 1000000000;
BytesTotalPerSec = 34610;
var bytesTotal = (BytesTotalPerSec * 8);
var utilizationPerc = (CurrentBandwidth / bytesTotal) / 100;

This is not giving me the correct value, what am I doing wrong?


Solution

  • I figured out the issue, I had to explicitly declare a double:

    var output2 = (double)BytesTotalPerSec / TotalBW;