Reputation: 414
I'm new in asp.net. Im develping a web-baised application that should prevent the user if he tried to login three times with wrong password.
I will disable the login button for 10 minutes then I will enable it.
this is the interface
and this is the timer code
protected void timer1_tick(object sender, EventArgs e)
{
timer--;
if (timer == 0)
{
Button1.Enabled = true;
Timer1.Enabled = false;
Label1.Visible = false;
}
}
but when I run the application, after 10 minutes it's refresh the page without enable the login button
Upvotes: 1
Views: 1620
Reputation: 137128
If you are using a System.Tmers.Timer
then simply call:
Timer1.Start();
If you are using a System.Threading.Timer
then this should start immediately. The third argument in the constructor is the dueTime
which is:
The amount of time to delay before callback is invoked, in milliseconds. Specify Timeout.Infinite to prevent the timer from starting. Specify zero (0) to start the timer immediately.
So if this is non-zero your timer wont fire for the first time until after both the dueTime
and period
have elapsed. So if you have:
var timer1 = new Timer(callback, state, 10000, 10000);
the first time this will fire will be after 20 seconds and then it will fire every 10 seconds thereafter. If you want it to fire every 10 seconds then you need to specify 0 as the dueTime
:
var timer1 = new Timer(callback, state, 0, 10000);
Upvotes: 2