• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

Timing last user input

I need to implement a background processing thread in my Windows app. The thread should “wake up” one hour after the last user interface activity, and run some time-consuming maintenance functions, like file backups. The idea behind one hour is to activate the thread when the app is not actively used.

How can I detect that there was no user interface activity for a certain period of time? Inserting some checkpoints into the user input functions (like OnMouseMove or OnKeydown) is hardly an option, since there is a lot of interface-related functions in my app. Is there a more elegant way to do it?
1 Solution
olegspAuthor Commented:
Well, looks like I need some 100 lines of code to properly set the trigger, and it is guaranteed to work for Win 2000/XP only...

Indeed, "Microsoft-elegant" :o( ...

With this option it is really easier for me just to add a single timing line to all my user-interface functions!
Check out this MSJ Q&A column where Paul DiLascia discusses some options: http://www.microsoft.com/msj/0200/c++/c++0200.asp

 lpi.cbSize = sizeof(lpi);

 DWORD dwIdleTime = lpi.dwTime;

(Win98/W2k and above)

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Forgot to mention, there is also code for systems that are older.
If you are a system administrator trying to set this things or just doing it for yourself then make you app into a screen saver and have windows screensaver wait 60 minutes to start. This way windows will call you program when the screen saver starts. Screen savers are fairly easy to create, basically just rename the file to .scr and your off.  You can do a simple search on the web for some other screen saver how to's;

If Windows 98 and 95 are your fancy then screen saver is the way to go.
olegspAuthor Commented:
No, I am not a sysadmin, but I am writing an app which is supposed to run for a long period of time and, when idle, will need to do some backups and cleanup of its data files. So screensaver is not really a good option... Looks like jkr's suggestion is the easiest so far...
>>Looks like jkr's suggestion is the easiest so far

So, any ends still open?
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to jkr: Grade A

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).


-bcl (bcladd)
EE Cleanup Volunteer

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now