tan
站在牛顿头上吃苹果的程序员

   DisppatcherTimer是一个比较常用的计时器对象,其使用非常简单,位于using System.Windows.Threading命名空间下,如下演示一个获取系统时间的例子:

        public CygBrowser()
        {
            InitializeComponent();          
            DispatcherTimer timer = new DispatcherTimer();
            //设置一个间隔时间
            timer.Interval = new TimeSpan(0, 0, 1);
            //事件处理
            timer.Tick += new EventHandler(timer_Tick);            
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            textBlock1.Text = "当前系统时间为:"+DateTime.Now.ToLongTimeString();
        }

  

posted on 2011-11-25 14:40  tanliang  阅读(539)  评论(0编辑  收藏  举报