B4J Question cpu load

bogdanc

Active Member
Licensed User
Longtime User
Hi!

I'm trying to get a CPU load.
for one of the PC that I tried check getting a value -100
instead of real value: 60% etc

here is my simple code:

B4X:
    Dim CPULoad As AWTRobot
Dim cpLoad As Int =NumberFormat ( (CPULoad.SystemCPULoad*100) ,0,2   )

what could cause the issue.

Thanks for any help.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Sometimes the call will fail. There's nothing that can be done about it but in my experience it's pretty rare. If you are calling SystemCPULoad numerous times throughout the run time of your program, most of the calls should return correct values.
 
Upvote 0

bogdanc

Active Member
Licensed User
Longtime User
Sometimes the call will fail. There's nothing that can be done about it but in my experience it's pretty rare. If you are calling SystemCPULoad numerous times throughout the run time of your program, most of the calls should return correct values.

Hi.
Thanks for replay.

For some reason on that PC shows alwyas -100.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Even if you try calling SystemCPULoad periodically with a Timer? What operation system is on that PC?
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
And it reports -100 every time? That's very strange. It works perfectly on my Windows 7 machines (32 and 64 bit) and RasPi2. What Java version are you using?

Just to be clear, you're declaring the AWTRobot as a Global variable once and then calling SystemCPULoad inside your Timer_Tick event, right? You're not declaring a new AWTRobot each time inside Timer_Tick, right?
 
Upvote 0
Top