WPF单线程定时器 简单实例

时间:2014-05-09 03:27:00   收藏:0   阅读:366
bubuko.com,布布扣
        //窗体加载完毕
        void MyMessageBox_Loaded(object sender, RoutedEventArgs e)
        {
            //启动定时期倒计时,多线程计时
            //System.Threading.Timer timer;


            //启动单线程计时
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Tick += ShowTimeTick;
            timer.Start();
        }


        //定时修改计时时间
        private void ShowTimeTick(object sender, EventArgs e)
        {
            timeTick.Content = TimeSpan + "秒后,自动关闭...";
            if (TimeSpan == 0)
            {
                this.Close();
            }
            TimeSpan--;
        }
bubuko.com,布布扣

 

WPF单线程定时器 简单实例,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!