Software > Computer programming

Run a program only on idle time - Screensaver Creation Question


I have a project that I am playing with to which I'd like to have it running on my computers only during idle time and then when computer is in use it either pauses the program or runs it at a much lesser CPU priority so that it doesn't cripple the system when hopping on to use it.

Currently I set it to run with a core affinity setting on how hard I want it to hit the cores of the quadcore system. But was thinking if I could wrap this exe that was programmed in C++ around a screensaver and set it to only run when idle, that would make more sense vs stopping the exe and going about what i am doing and then having to click on the shortcut to run it when I am done what i am doing to pick up where it left off.

I've never dabbled in screensaver programming, but interested in learning how to take what I have and make it a screensaver compatible program. I am looking to run it on two computers a Windows 7 and 10 system. Not sure if there are any differences in compatibility to make it work with 1 vs the other or if a screensaver written for 7 is automatically Windows 10 compatible.

Some of the questions I have are ones that the answers in the wrong hands could be used to make a malicious screensaver etc. So I am thinking that maybe someone responding here with interest in assisting me on this via PM might be the smart way to go with this vs posting information here which could be used as a cookbook to making a bad screensaver.  :-\

Biggest question I was curious about was if there was a screensaver wrapper that exists to be able to wrap a program around a screensaver shell and have rules for this shell on how the EXE should behave when idle and how it should behave when the computer is suddenly in use my myself or my wife? I did a google search and didnt find anything helpful on a wrapper to make any program created run only when idle and then go dormant or run very slowly when the computer is in use to not impact myself and my wife as users of these 2 computers.

Because I didnt see a wrapper out there, maybe I need to program up a screensaver and add my code to it, but never done it before and figured I'd check here to see if anyone was able to point me in the right direction to myself coding up one that would work for myself.

A screensaver is just a normal executable renamed to SCR. Windows runs it after the screensaver timeout and it can do whatever it wants. (Obviously, screensavers tend to show full-screen graphics and exit out as soon as you move the mouse or press a key)

it is configured in the registry under each user profile. HKEY_USERS\.DEFAULT\Control Panel\Desktop has a SCRNSAVE.EXE key which would have the full path to any configured screensaver executable. (It might let you use exe there come to think of it?)

As a screensaver I'd probably have the screensaver create a Window and then make it transparent via Layered Attributes with opacity 0, then if it detects any mouse movement or key presses it removes the window, does any needed cleanup for whatever it was doing, and exits.

An alternative approach could be to simply use task scheduler. Configure a repeating task for say every 10 minutes and set the option to "only execute when computer is idle for " option, "stop if the computer ceases to be idle" and "restart if the idle state resumes". Every 10 minutes task scheduler will check the conditions and start your background program, then close it when somebody uses it. (Which probably won't work well if you had the idea to use a console application...)

Thank You BC for this info... As far as the program opening and closing multiple times I have no problem with that as for it writes to a file of where it left off, however if the program was interrupted/ended during the write process it would corrupt the file it writes to or if it ends before the file close instruction was executed,... I am not sure how a program with a file open without a file close instruction would affect the system, however it might make for a memory leak because the proper file close instruction wasn't completed. So with each new instance of that program run and abnormally terminated it might not release the memory address that was used for the write to file instruction because the file close never completed.

The scheduled task idea that you shared to trigger every 10 minutes and if user is active ignore and if idle run it until active, I never thought of and actually that would be really easy to implement. It also seems the better route to go since it is a console program. I forgot about the ability to set scheduled tasks to trigger conditionally to system idle.

I just need to figure out how much of a problem it would be if the executable is interrupted during a file write which I am not sure if a program in a loop would wait to the end of the loop before exiting which is the safest point of an exit after the file close instruction has completed, or if its like taskkill and kills the program dead in the water no matter of how critical in the execution it is processing.

For normal Windows applications you can handle WM_CLOSE of the main window. For Console applications you might be able to detect when the program is exited by using SetConsoleCtrlHandler(). In each case you can do the appropriate "cleanup" to store what the current state of the task is.

Cool... Thanks for your help BC!  :)


[0] Message Index

Go to full version