Extensions.cs 848 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Windows.Threading;
  3. namespace MediaBrowser.UI.Extensions
  4. {
  5. public static class Extensions
  6. {
  7. /// <summary>
  8. /// Invokes an action after a specified delay
  9. /// </summary>
  10. /// <param name="dispatcher">The dispatcher.</param>
  11. /// <param name="action">The action.</param>
  12. /// <param name="delayMs">The delay ms.</param>
  13. public static void InvokeWithDelay(this Dispatcher dispatcher, Action action, long delayMs)
  14. {
  15. var timer = new DispatcherTimer(DispatcherPriority.Normal, dispatcher);
  16. timer.Interval = TimeSpan.FromMilliseconds(delayMs);
  17. timer.Tick += (sender, args) =>
  18. {
  19. timer.Stop();
  20. action();
  21. };
  22. timer.Start();
  23. }
  24. }
  25. }