using System;
using System.Windows;
using System.Timers;
using System.Windows.Threading;

namespace TimerTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
    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

相关文章:

  • 2022-01-01
  • 2022-12-23
  • 2021-09-04
  • 2021-12-30
  • 2021-10-19
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2021-04-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案