using System;using System.Windows;using System.Timers;using System.Windows.Threading;namespace TimerTest{////// Interaction logic for MainWindow.xaml/// public partial class MainWindow : Window { private Timer aTimer = null; private delegate void TimerDispatcherDelegate(); public MainWindow() { InitializeComponent(); aTimer = new Timer(1000); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Interval = 1000; aTimer.Enabled = true; } private void OnTimedEvent(object sender, EventArgs e) { this.Dispatcher.Invoke(DispatcherPriority.Normal, new TimerDispatcherDelegate(updateUI)); } private void updateUI() { timeLabel.Content = DateTime.Now.ToUniversalTime(); } }}
http://www.cnblogs.com/zhchbin/archive/2012/03/06/2381693.html