Hey guys,
Long story short, I need my PB app to run only while the computer is idle. Currently it runs as a scheduled task, every 15 minutes or so it checks for some work on the server and if it has some then it churns away at it. Any idea how to do this? I was thinking maybe read the process list and look for a screensaver? Maybe there's some kind of library that I can link to that already does it? Or a process manager.... I'm completely at a loss. Google doesn't seem to be helping and I can't find anything on the forum already.
Any ideas?
Automatic Process Manager
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Automatic Process Manager
The only way to really check for a screensaver for me has been to set a timer, and every time the timer runs set the current time in a variable. Next time the timer runs - look at the difference between these two numbers and if its greater than ... 20 minutes (in your case) then it means that the computer has been sleeping. Altert the user to turn off screen saver.
Re: Automatic Process Manager
Jesper: Thank you! That is an interesting idea. I'm more concerned in having my program run like a screen saver. In other words, I would like it to only run while the computer is idle. Something like this:
How would I check to see if the computer is idle?
I was just thinking, maybe I could monitor the mouse position. So if the mouse isn't moving for 5 minutes then I can assume it's safe to run. Hmmm. It's an interesting problem because that would require my PB script to actively monitor the mouse even when it didn't have focus. And I would need to monitor the keyboard too, since maybe they're typing a letter or something. My program would probably look like a keylogger!
Code: Select all
If ComputerIsIdle()
CheckForWork()
Else
Delay(5000)
EndIf
I was just thinking, maybe I could monitor the mouse position. So if the mouse isn't moving for 5 minutes then I can assume it's safe to run. Hmmm. It's an interesting problem because that would require my PB script to actively monitor the mouse even when it didn't have focus. And I would need to monitor the keyboard too, since maybe they're typing a letter or something. My program would probably look like a keylogger!

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Automatic Process Manager
Perhaps the goal should be more towards a low-level of use rather than completely idle. Is your app really so disruptive that it should not run even if the User is only typing a memo in Notepad?
Dectecting how busy the CPU is might be an option: http://www.purebasic.fr/english/viewtop ... 13&t=46347
Dectecting how busy the CPU is might be an option: http://www.purebasic.fr/english/viewtop ... 13&t=46347
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Automatic Process Manager
I just realized that I might be going about this wrong, it turns out that scheduled tasks have this option already. So this just got a LOT easier. lol
http://www.microsoft.com/resources/docu ... x?mfr=true
I guess this is why nobody bothered to ask before. I was thinking of how to program this, but I think relying on the windows implementation is the best.
http://www.microsoft.com/resources/docu ... x?mfr=true
I guess this is why nobody bothered to ask before. I was thinking of how to program this, but I think relying on the windows implementation is the best.
Re: Automatic Process Manager
You also can just set the process priority class to #IDLE_PRIORITY_CLASS and thread priority to #THREAD_PRIORITY_IDLE.
So the process could run all the time but only get's CPU time not needed by any other process.
So the process could run all the time but only get's CPU time not needed by any other process.
Re: Automatic Process Manager
Have you already taken a look into this old code example
from Rings in which he demonstrated how to detect when
the processor is entering idle state?
http://www.purebasic.fr/english/viewtopic.php?t=19712
from Rings in which he demonstrated how to detect when
the processor is entering idle state?
http://www.purebasic.fr/english/viewtopic.php?t=19712
Re: Automatic Process Manager
Code: Select all
Structure lastinputinfo
cbSize.i
dwTime.l
EndStructure
Define var.lastinputinfo
var\cbSize = SizeOf(LASTINPUTINFO)
Delay(1000)
GetLastInputInfo_(@var)
Debug GetTickCount_() - var\dwTime
Re: Automatic Process Manager
Thanks guys for the help, I decided to go with the option of letting windows do my task scheduling. Not sure if it isn't easier to just write it myself though, lol. Windows is being a total jerkface about adding a scheduled task from a Byteessentials Installer script. I may just end up writing it myself and using one of these suggestions. 
