Timer problem

G

Guest

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(object sender, EventArgs e)
{


this.timer = new Timer();
this.timer.Interval = 25000;
this.timer.Tick += new EventHandler(this.timer_Tick);
Application.Idle += new EventHandler(this.Application_Idle);

}

void Application_Idle(object sender, EventArgs e)

{
this.timer.Stop();
this.timer.Start();
}

void timer_Tick(object sender, EventArgs e)

{
frmLogin form = new frmLogin();
form.ShowDialog();
}
 
P

Peter Duniho

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.Idle 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
 
G

Guest

Sorry about ms and ns error. Actually the code/algorithm that is used was not
developed by me. I actually got it as a reply to an earlier question in this
forum. I am trying to digest your reply in order to make appropriate changes.
Thank you.
 
G

Guest

I have not found a suitable way to get this done. I'm googling to find a
solution.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top