Solved

# PerformanceCounter.NextValue()

Posted on 2011-04-22
455 Views
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
Question by:databoks

LVL 35

Expert Comment

This method returns a float. you can cast it:
float myFloatValue = 10.3F;
int myIntValue = (int)myFloatValue;
0

LVL 35

Expert Comment

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

LVL 8

Author Comment

What is the formel to calculate it to and int or a long?
0

LVL 35

Expert Comment

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

LVL 35

Accepted Solution

Can databoks explain how his/her fixed solution is different from mine?
0

LVL 8

Author Comment

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

LVL 8

Author Comment

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

### Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
how to add IIS SMTP to handle application/Scanner relays into office 365.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…