Heres the problem.
I have an mdi child form called "MyChild".
I need to refresh this form by calling the "MyRefresh()" method if the form has focus, and no controls have been clicked on in this form for the last 60 seconds.
Is there an efficient way of doing this ?
In the activate event of the form I could set up a timer and give it an interval of 60 seconds but what about checking for user intervention at any point in that 60 seconds ?
Can't you just reset the timer when user intervention takes place, eg when a button is clicked? I don't know if there's a Reset method on a timer, but Disabling, then Enabling it will probably work.
I think he is asking for an efficient way to actually do the idle tracking on the form. He probably doesn't want to call a routine or fire an event for 30-40 controls..
That was really why I was asking which version, because a good solution would just to use some recursion to add an event handler to all controls that you care about monitoring, to call a routine to signal a timestamp should be set. Depending on the version, you could use LINQ to make it easier to grab the controls you want.
This timestamp would indicate the last time a given control was touched. The timer should never actually be stopped. It could be running at an interval of 1000, and doing checks to see if the time since the last timestamp is a minute ago, and if so, do what needs to be done.
Sorry about the delay and the lack of version info.
Anyways I am using 2.0 and you are correct. I don't want to get every control on the form to have to fire off something every time someone goes near it.
Recursion sounds interesting though I can't say I'm too familiar with it.
well you said only when the user clicks something you want to then consider that the user is still active right?
Here is some sample code. You may want to modify it to only add handlers to certain control types, otherwise you end up adding them to all controls on the form (like labels and whatnot) That may or may not be desirable.