I try to make button click by wait x second over this button then perform his action, I use System.Windows.Forms.Timer
to make that in Win-form
but how can make the same thing in WPF.
I make this function to wait for 5 second before make some action
private System.Windows.Forms.Timer MTimer = new System.Windows.Forms.Timer();
private void StartAsyncTimedWork()
{
MTimer.Interval = 5000;
MTimer.Tick += new EventHandler(MTimer_Tick);
MTimer.Start();
}
How i can make the same thing in Wpf and make the user over the button by the mouse and wait for 5 second before perform button action, Can please give me a link or bit of code.
Well you could use a DispatcherTimer
instead, but it's probably simplest to use an async
method and Task.Delay
:
public async void Foo(object sender, RoutedEventArgs e)
{
await Task.Delay(5000);
DoSomething();
}
See more on this question at Stackoverflow