[WPF] Delay the Execution of a method

Delaying the execution of code in WPF applications? Buy a slower computer or use this code.

Today, something almost embarrassing happened to me.

In one of my WPF projects I wanted a method to execute after a specified delay.

I played around with the Dispatcher class and soon discovered the method Dispatcher.Invoke(DispatcherPriority, TimeSpan, Delegate). I neither looked into the Doku nor at the IntelliSense popup (I don’t know where my mind was at that time 😀 ) and used the method.

Then I really desperated debugging that code. The delegate was always invoked at once.

Read the rest of this entry »