I need to disable the button for 1.5 seconds in one application that I am writing. An image is displayed, the user presses a button, and then another image is displayed. I need to make sure that the user does not click the button too quickly.
So, when the image is displayed, I call this function:
System.Timers.Timer mTimer;
void TimerStart() {
Done.IsEnabled = false;
mTimer = new System.Timers.Timer();
mTimer.Interval = 1500;
mTimer.Start();
mTimer.Elapsed += new System.Timers.ElapsedEventHandler(TimerEnd);
}
TimerEnd code looks like this:
void TimerEnd(object sender, EventArgs eArgs) {
if (sender == mTimer){
Done.IsEnabled = true;
mTimer.Stop();
}
}
The line "Done.IsEnabled" hits, but the button is not re-enabled, and the timer does not stop shooting. What am I doing wrong here? If that matters, this is a WPF application.
source
share