Wednesday, 21 November 2012

Delay in Silverlight

public class ActionDispatcherTimer : System.Windows.Threading.DispatcherTimer
{
public Action Action { get; set; }
}

public static class UIHelper
{
public static void DelayStart(int milliseconds, Action action)
{
var timer = new ActionDispatcherTimer
{
Interval = new TimeSpan(0, 0, 0, 0, milliseconds),
Action = action
};
timer.Tick += onTick;
timer.Start();
}

private static void onTick(object sender, EventArgs arg)
{
var t = sender as ActionDispatcherTimer;
t.Stop();
t.Action();
t.Tick -= onTick;
}
}

//usage: after 5 seconds execute ths lambda
UIHelper.DelayStart(5000, () => status = "Completed");


Taken from:  http://blog.bodurov.com/How-to-Create-setTimeout-Function-in-Silverlight/

No comments:

Post a Comment