2013年4月23日 星期二

[Windows 8] How to use the timer in the Windows Store Application by C#

// defines
private DispatcherTimer _timer;

// Init
_timer= new DispatcherTimer();
_timer.Tick += _timer_Tick;
_timer.Interval = new TimeSpan(0, 0, 1);

...
_timer.Start();                 // start timer


private void _timer_Tick(object sender, object e)
{
   // do something
}

_timer.Stop();                 // stop timer
_timer.Tick -= _timer_Tick;    // delete function reference

Reference:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dispatchertimer(v=win.10).aspx

沒有留言:

張貼留言