一、前言
引用命名空间后直接创建添加Tick事件,就可以start使用,非常简单。
二、例子
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Click);
timer.Interval = new TimeSpan(0,0,0,0,3000);// 天,时,分,秒,毫秒
timer.Start();
void timer_Click(object sender, EventArgs e)
{
this.Close();
}
三、结束语
-
注意时分秒的设置。
-
更新UI的话,使用方法:
this.Dispatcher.BeginInvoke((Action)delegate ()
{ //执行跨线程访问 } );