in reply to when CPU is idle

I don't think that programs that should only run when idle check the CPU usage. They simply tell the OS to set their priority to the lowest level. You may want to look into that instead.