Results 1 to 8 of 8

Thread: Advice on refreshing form after n seconds

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Advice on refreshing form after n seconds

    Hi All,

    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 ?

    Parksie

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Advice on refreshing form after n seconds

    What version of .NET?

  3. #3
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Advice on refreshing form after n 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.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Advice on refreshing form after n seconds

    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.

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Advice on refreshing form after n seconds

    Hi kleinma,

    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.

    Parksie

  6. #6

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Advice on refreshing form after n seconds

    Oooops.

    Sorry about the double post.

    Jeez. Is it just me or is this forum getting very sluggish?

    Parksie

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Advice on refreshing form after n seconds

    yes very slow today....

    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.
    Attached Files Attached Files

  8. #8

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Resolved Re: Advice on refreshing form after n seconds

    Thanks kleinma.

    Thats a really tidy solution. just what I was looking for.

    Parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width