I have a program that occasionally needs to scan some directories recursively (an improvement for this part of the program is in the pipeline, but won't be ready for a while). To avoid the user having to wait for this scanning, I would like to do the scanning while the user isn't using my program when possible.
I intend to implement it by running a timer that checks for idle time. I've found the following for checking system idle time: http://www.delphitips.net/2007/11/11/how-to-detect-system-idle-time/
This would be functional, but I would prefer to activate the function even when the user is working with other programs on the same computer. This way, if he switches to another program, I could catch up on the scanning I need to do.
I realize that I could do the scanning in a background thread, and either that or some sort of windows hooks will be implemented at some point, but not just yet.
EDIT: The goal here is a relatively easy change to the program to do any scanning that might be queued while the user isn't actively using MY application. The scanning isn't especially intensive, but it isn't done in a thread, and therefore freezes my app while in progress. Basically, I'm looking for a quick win while I'm working on a more long term solution.
Idle time is the amount of time spent waiting to use viable equipment, or the nonproductive time of employees due to lack of demand or unforeseen work stoppage. If you don't have a piece of equipment scheduled to run, or an asset is up and available but not being used, that's considered idle time.
What you need is a separate thread that will be resumed when the system is idle or paused when there is activity. A simple way to do this is to place a Timer Component and check if the system is idle and thread is suspended or not use ResumeThread ,SuspendThread
Look here
http://pastebin.com/8X9Sg42H i crafted something for your situation enjoy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With