Grayda
Member
- Joined
- May 20, 2010
- Messages
- 16
- Programming Experience
- 10+
I'm building a VB.NET 2010 app that tracks battery usage. Run the app, start logging, then let the battery go flat. At the end, you get a nice graph that shows you how long the battery took to run down. Compare it to previous results and you can see how battery life is doing.
But this is supposed to be an unattended app, so it's not feasible for me to sit down and use word, browse the Internet, listen to music, play games etc. for four hours (especially at work!), so I'm looking for a way to artificially increase CPU usage to chew through the battery faster, and simulate how a battery would probably be used throughout a work day.
I've managed to inflate the memory usage using:
And deflate it by:
But that doesn't really seem to have any effect on battery time, as that memory isn't being used, just allocated.
How would you suggest I increase CPU usage in VB.NET? I've tried creating new threads with constant loops, but I get the funny feeling that VB.NET optimizes these kind of things to prevent memory and CPU hogging apps from taking over
But this is supposed to be an unattended app, so it's not feasible for me to sit down and use word, browse the Internet, listen to music, play games etc. for four hours (especially at work!), so I'm looking for a way to artificially increase CPU usage to chew through the battery faster, and simulate how a battery would probably be used throughout a work day.
I've managed to inflate the memory usage using:
VB.NET:
Dim a as long
Dim ptr(0 To 20000) As IntPtr
For a = 1 To 20000
ptr(a) = System.Runtime.InteropServices.Marshal.AllocHGlobal(65535)
Debug.WriteLine("Memory block #" & a & " allocated")
Next
And deflate it by:
VB.NET:
For a = 1 To 20000
System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr(a))
Debug.WriteLine("Memory block #" & a & " freed")
Next
But that doesn't really seem to have any effect on battery time, as that memory isn't being used, just allocated.
How would you suggest I increase CPU usage in VB.NET? I've tried creating new threads with constant loops, but I get the funny feeling that VB.NET optimizes these kind of things to prevent memory and CPU hogging apps from taking over