Personally, I think Thread.Sleep is a bad implementation. It blocks the user interface, etc. I personally like the timer implementation, as it waits, then it fires.
Usage: DelayFactory.DelayAction(500, new Action(() => { this.RunAction(); }));
//Note Forms.Timer and Timer() have similar implementations. public static void DelayAction(int millisecond, Action action) { var timer = new DispatcherTimer(); timer.Tick += delegate { action.Invoke(); timer.Stop(); }; timer.Interval = TimeSpan.FromMilliseconds(millisecond); timer.Start(); }
Mark Rowe Dec 27 '13 at 10:30 2013-12-27 10:30
source share