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");
            }

  • 相关阅读:
    如何在markdown隐藏代码块
    html基础
    驻留机制
    字典
    echarts简单使用
    selenium的基本操作
    Excel上传、下载、models 自定义字段、批量执行(可选)
    django之自定义标签(路径url反向解码)
    邮件自动生成发送用例报告
    前台获取后台保存的数据
  • 原文地址:https://www.cnblogs.com/z-huan/p/7443279.html
Copyright © 2011-2022 走看看