public
Created

DelayedExecuter

  • Download Gist
DelayedExecuter.cs
C#
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 27 28 29 30 31 32 33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
 
namespace NilzorLib.Metro.Core
{
public class DelayedExecuter
{
DispatcherTimer _timer;
 
public static void ExecuteAfter(int ms, Action action)
{
ExecuteAfter(new TimeSpan(0,0,0,0,ms), action);
}
 
public static void ExecuteAfter(TimeSpan span, Action action)
{
var p = new DelayedExecuter();
p._timer = new DispatcherTimer();
p._timer.Interval = span;
p._timer.Tick += (a,b) =>
{
p._timer.Stop();
p._timer = null;
action();
};
p._timer.Start();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.