Timer problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RGF2ZQ==?=

    Timer problem

    I am trying to use the timer to make a login form show after a specified
    interval. However, if the interval is set to a value greater than 5000
    nanosecond, then it does not respond. What could be the issue here? Thanks.


    private void frmMain_Load(ob ject sender, EventArgs e)
    {


    this.timer = new Timer();
    this.timer.Inte rval = 25000;
    this.timer.Tick += new EventHandler(th is.timer_Tick);
    Application.Idl e += new EventHandler(th is.Application_ Idle);

    }

    void Application_Idl e(object sender, EventArgs e)

    {
    this.timer.Stop ();
    this.timer.Star t();
    }

    void timer_Tick(obje ct sender, EventArgs e)

    {
    frmLogin form = new frmLogin();
    form.ShowDialog ();
    }
    --
    L. A. Jones
    --
    L. A. Jones
  • Peter Duniho

    #2
    Re: Timer problem

    On 2007-11-03 12:31:00 -0700, Dave <Dave@discussio ns.microsoft.co msaid:
    I am trying to use the timer to make a login form show after a specified
    interval. However, if the interval is set to a value greater than 5000
    nanosecond, then it does not respond. What could be the issue here? Thanks.
    First, you can't specify a "5000 nanosecond" timer delay. The timer
    interval is in milliseconds (thousandths of a second).

    Secondly, did you check to see whether the Application.Idl e event is
    being raised multiple times? You ask "what could be the issue here?"
    and the obvious answer is that if the Idle event is raised before the
    timer expires, then you reset the timer and start all over, never
    allowing the timer interval to expire.

    I haven't bothered to test the code you posted, but just looking at it,
    the Idle event seems like the most likely culprit.

    I also find it interesting that with the design you've chosen, your
    login dialog could pop up even after the application is no longer idle
    again. You don't bother to stop the timer until the next time the Idle
    event is raised, so if you've started the timer and it expires before
    the application reaches the idle state again, the Tick event will be
    raised and cause the login dialog to be shown, even though the
    application hasn't been idle.

    Pete

    Comment

    • =?Utf-8?B?RGF2ZQ==?=

      #3
      RE: Timer problem

      I have not found a suitable way to get this done. I'm googling to find a
      solution.
      --
      L. A. Jones


      "Dave" wrote:
      I am trying to use the timer to make a login form show after a specified
      interval. However, if the interval is set to a value greater than 5000
      nanosecond, then it does not respond. What could be the issue here? Thanks.
      >
      >
      private void frmMain_Load(ob ject sender, EventArgs e)
      {
      >
      >
      this.timer = new Timer();
      this.timer.Inte rval = 25000;
      this.timer.Tick += new EventHandler(th is.timer_Tick);
      Application.Idl e += new EventHandler(th is.Application_ Idle);
      >
      }
      >
      void Application_Idl e(object sender, EventArgs e)
      >
      {
      this.timer.Stop ();
      this.timer.Star t();
      }
      >
      void timer_Tick(obje ct sender, EventArgs e)
      >
      {
      frmLogin form = new frmLogin();
      form.ShowDialog ();
      }
      --
      L. A. Jones
      --
      L. A. Jones

      Comment

      • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

        #4
        RE: Timer problem

        I suggest that Peter's help is better than you will find via Google.

        Your idle event is starting the timer. You are getting an idle event any
        time app is waiting, which I'm guessing, is most of the time your app is
        running. I believe if you want your app to show the dialog every interval,
        you don't want the idle event handler. Is it possible you are trying to get
        the time that the user has been idle and not the application? I'm sure
        screensavers use something along those lines and you should follow suit.

        "Dave" wrote:
        I have not found a suitable way to get this done. I'm googling to find a
        solution.
        --
        L. A. Jones
        >
        >
        "Dave" wrote:
        >
        I am trying to use the timer to make a login form show after a specified
        interval. However, if the interval is set to a value greater than 5000
        nanosecond, then it does not respond. What could be the issue here? Thanks.


        private void frmMain_Load(ob ject sender, EventArgs e)
        {


        this.timer = new Timer();
        this.timer.Inte rval = 25000;
        this.timer.Tick += new EventHandler(th is.timer_Tick);
        Application.Idl e += new EventHandler(th is.Application_ Idle);

        }

        void Application_Idl e(object sender, EventArgs e)

        {
        this.timer.Stop ();
        this.timer.Star t();
        }

        void timer_Tick(obje ct sender, EventArgs e)

        {
        frmLogin form = new frmLogin();
        form.ShowDialog ();
        }
        --
        L. A. Jones
        --
        L. A. Jones

        Comment

        Working...