aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.UI/Extensions/Extensions.cs
blob: 1d0d7d1c2d48c39af52e5ee784aeebe2d4afffbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Windows.Threading;

namespace MediaBrowser.UI.Extensions
{
    public static class Extensions
    {
        /// <summary>
        /// Invokes an action after a specified delay
        /// </summary>
        /// <param name="dispatcher">The dispatcher.</param>
        /// <param name="action">The action.</param>
        /// <param name="delayMs">The delay ms.</param>
        public static void InvokeWithDelay(this Dispatcher dispatcher, Action action, long delayMs)
        {
            var timer = new DispatcherTimer(DispatcherPriority.Normal, dispatcher);
            timer.Interval = TimeSpan.FromMilliseconds(delayMs);
            timer.Tick += (sender, args) =>
                {
                    timer.Stop();
                    action();
                };
            timer.Start();
        }
    }
}