zoukankan      html  css  js  c++  java
  • DispatcherTimer和Timer(计时器)

    System.Windows.Threading.DispatcherTimer dTime;
            System.Timers.Timer timer;
            public MainWindow()
            {
                InitializeComponent();
                if (dTime == null)
                {
                    dTime = new System.Windows.Threading.DispatcherTimer();
                    dTime.Interval = new TimeSpan(0, 0, 1);
                    dTime.Tick += DTime_Tick;
                    dTime.Start();
                }
                if (timer == null)
                {
                    timer = new System.Timers.Timer();
                    timer.Interval = 1000;
                    timer.Elapsed += Timer_Elapsed;
                    timer.Start();
                }
            }
            private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                this.Dispatcher.BeginInvoke(new Action(()=> {
                    this.timeLable.Content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }));
            }
            private void DTime_Tick(object sender, EventArgs e)
            {
                this.dTimeLable.Content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }

  • 相关阅读:
    poj 1200 crasy search
    cdoj 1092 韩爷的梦
    fzu 2257 saya的小熊饼干
    zoj 3950 how many nines
    zoj 3963 heap partion
    fzu 2256 迷宫
    fzu 2253 salty fish
    hdu 2473 Junk-Mail Filter
    codeforces 129B students and shoes
    hdu 3367 Pseudoforest
  • 原文地址:https://www.cnblogs.com/z-huan/p/7443279.html
Copyright © 2011-2022 走看看