zoukankan      html  css  js  c++  java
  • 定时器例子

     int countSecond = 5;
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                DispatcherTimer disTimer = new DispatcherTimer();
        disTimer.Interval = new TimeSpan(0, 0, 0, 1); //参数分别为:天,小时,分,秒。此方法有重载,可根据实际情况调用。
        disTimer.Tick += new EventHandler(disTimer_Tick); //每一秒执行的方法
        disTimer.Start();
            }
            void disTimer_Tick(object sender, EventArgs e)
            {
                if (countSecond == 0)
                {
                    MessageBox.Show("结束");
                }
                else
                {
                    //判断TextBox是否处于UI线程上
                    if (TextBox.Dispatcher.CheckAccess())
                    {              
                        TextBox.Text = countSecond.ToString();
                    }
                    else
                    {
                        TextBox.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                       {
                            TextBox.Text = countSecond.ToString();
                        }));
     
                    }
                    countSecond--;
                }
     
            }
  • 相关阅读:
    VOIP开源项目源码地址(一)
    iptables下udp穿越实用篇
    function socket about http://net.pku.edu.cn/~yhf/linux_c/function/14.html
    IOKE的SIP协议专栏
    XviD core API overview: Decoding
    Socket about
    sql海量数据优化
    Socket、多线程、消息队列、共享资源并发下的性能研究
    【转】SQL 索引理解
    SQL 索引理解
  • 原文地址:https://www.cnblogs.com/xiaoyaodijun/p/4030553.html
Copyright © 2011-2022 走看看