zoukankan      html  css  js  c++  java
  • DispatcherTimer和Timer的区别

    两者区别是 Timer在非UI线程跑的,DispatcherTimer是在UI线程跑的,

    DispatcherTimer 可以直接更新UI

    Timer必须使用this.Dispatcher.BeginInvoke去更新UI        

    private void DisPatcherTimerMethod()

            {
                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromMilliseconds(1000);
                timer.Tick += Timer_Tick;
                timer.Start();
            }
            private void Timer_Tick(object sender, EventArgs e)
            {
                this.label1.Text = DateTime.Now.ToString();
            }
            private void TimerMethod()
            {
                System.Timers.Timer tmr = new System.Timers.Timer(1000); //1秒一个循环
                tmr.Elapsed += tmr_Elapsed;
                tmr.Start();
            }
            private void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.label2.Text = DateTime.Now.ToString();
                }), null);
            }
  • 相关阅读:
    php实现rpc简单的方法
    统计代码量
    laravel的速查表
    header的参数不能带下划线
    PHP简单实现单点登录功能示例
    phpStorm函数注释的设置
    数据结构基础
    laravel生命周期和核心思想
    深入理解php底层:php生命周期
    Jmeter:实例(性能测试目标)
  • 原文地址:https://www.cnblogs.com/LCLBook/p/11504500.html
Copyright © 2011-2022 走看看