wpf计时器

wpf应用程序间隔一段时间触发一个事件,代码如下:

       public MainWindow()
        {
            InitializeComponent();
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += MyEventHandler;
            timer.Start();
        }

        public void MyEventHandler(object sender, EventArgs e)
        {

            tbxTime.Text = DateTime.Now.ToString("yyyy/MM/dd HH:m:ss");
        }

 

转载于:https://www.cnblogs.com/527289276qq/p/5279751.html

你可能感兴趣的:(wpf计时器)