I have a console app that sits idle much of the time and I want the impact on the user machine to be minimal. The app has a timer (set to 1 minute) and a couple of sockets. Some Windows PCs with one CPU are reporting high application CPU usage even when my app is idle (all other users report 0% CPU at idle time).
In the run time event loop should I use DoEvents or DoEvents(30000) or doesn’t it have any impact on the application’s CPU?
depends on how long its OK for the app to wait before waking up in response to whatever its doing. I dont believe that DoEvents() will be interrupted for a timer event or a socket event or anything during the sleep period. The default time for DoEvents() is 10ms, on MacOS anyway, it may be different on windows. In my testing that does result in some CPU usage being reported, though not usually very much if youre just looping in it. When I increase it to 100ms DoEvents( 100) Then it reliably reads as 0% on every users machine Ive seen while still being within 100ms of accuracy for timers and very short delays on starting socket communications and such. I dont think you want 30000 unless you can somehow sync it with the timer event and you dont need to process any other event in the meantime.
Then maybe DoEvents(1000) would be a reasonable value to get the application CPU usage right down without affecting any timers. My problem is I don’t have any computers with 1 CPU to test it!
I know that Xojo only uses one CPU as this is why I use console applications with my WebApp. I also know that running Xojo apps on a single core machine slows the PC to a crawl (more than just half-speed compared with a 2 CPU PC). This is why I’m trying to ‘force’ Xojo to play nicely on a 1-CPU PC and was wondering if adjusting the DoEvents value is likely to help at all.
I have used 360000 as the delay between event loop execution in some of my projects. These are simple ones that I only want to run once a day, so every hour the app just checks the time and executes or not.
The fact you have sockets and needs the event loop to run in order for those event handlers to be triggered sets the minimum amount of time your app can sleep.
You could also adjust your sleep time depending on other factors for example maybe 10000 when the sockets aren’t connected, but 1000 (or less) when they are.