Telling how long an application has been idle

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

Hi, I have an application that shows new orders that need to be acted on. I
use a datagrid to list the orders. Some of the users like to leave the grid
up and wait for new orders to come in. The option of having a refresh
button has been rejected.

Is there a way to have a timer of some sort that could keep track of the
time the form is open and run a refresh routine every X number of minutes?

Any help is greatly appreciated.
 
Here's an approach that refreshes after some arbitrary idle time:

First, set up a timer with a suitable interval for automatic refresh. In its
tick event handler, put code to do the automatic refresh.

Then wire up an event handler to the Application.Idle event. This event will
fire when the app goes idle. In the Idle event handler, stop the timer if
it's currently running (so you can restart with the full interval), and then
start the timer.

This approach starts the refresh timer over every time the application comes
to life for any reason, and updates only after the app has been completely
idle for a suitable length of time. You might also consider inspecting the
grid in the tick event handler to see if there's been any actual change
since the last refresh, and bypass the refresh if there have been no
changes.

HTH,
Tom Dacon
Dacon Software Consulting
 
Back
Top