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).
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