[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

PerformanceCounter.NextValue()

The Performance Counter returns a value on the Category "Network interface" on the counter Current Bandwidth it returns 1E+08 when i execute the PerformanceCounter.Nextvalue() method.

How do i calculate this to be an integer that i can understand?
0
databoks
Asked:
databoks
  • 4
  • 3
1 Solution
 
Miguel OzSoftware EngineerCommented:
This method returns a float. you can cast it:
float myFloatValue = 10.3F;
int myIntValue = (int)myFloatValue;
0
 
Miguel OzSoftware EngineerCommented:
Just to complement my previous comment.
Casting can be used when you are sure the float value will be within the integer range.
You should do the conversion like:
        private int FloatToInt(float value)
        {
            if (value > int.MinValue || value <= int.MaxValue)
                return (int)value;
            else
                return int.MinValue;//Do something to deal with this error
        }
0
 
databoksAuthor Commented:
What is the formel to calculate it to and int or a long?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Miguel OzSoftware EngineerCommented:
It depends how big you expect the float number to be. If your number is less than int.MaxValue then int is enough ,else use "long"
For long is very easy just replace "int" in my previous code with long.
An alternative is to divide your float number by 1000 or 1000000 if you know you have to deal with big numbers only and it does not affect the order of magnitude that you are trying to monitor
0
 
Miguel OzSoftware EngineerCommented:
I provided answers to the original question. My points please.
Can databoks explain how his/her fixed solution is different from mine?
0
 
databoksAuthor Commented:
I was developing this but the project has been outsourced so i don't have to spend time to this.

Therefor i don't know if you solution has worked - and i don't have time to test it.

0
 
databoksAuthor Commented:
how can i know if the posted question is correct if i haven't testet it?

However i don't want to spend time on this anymore.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now