先如下定义一个定时器:
public DispatcherTimer dispatcherTimer;
然后在某处创建这个对象实例:
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
设定超时回调函数:
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
设定间隔(下方例子是10秒钟):
dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
启动定时器:
dispatcherTimer.Start();
定义超时回调函数:
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
// do something here...
}
时间: 2024-10-11 03:47:49