Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.01 KB

File metadata and controls

38 lines (29 loc) · 1.01 KB

Update the UI from a periodic timer

Performs the specified action at the specified interval in minutes.

using System;
using Windows.UI.Xaml;

public static void StartTimer(int intervalInMinutes, Action action)
{
    var timer = new DispatcherTimer();
    timer.Interval = new TimeSpan(0, intervalInMinutes, 0);
    timer.Tick += (s, e) => action();
    timer.Start();
}

Usage

StartTimer(5, () =>
{
    // Do something every five minutes.
});

See also

DispatcherTimer class
Lambda expressions (anonymous methods using the "=>" syntax)

The TrafficApp sample uses this method to update location travel info and freshness timestamps.