wpf应用程序间隔一段时间触发一个事件,代码如下:
public MainWindow() { InitializeComponent(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(1000); timer.Tick += MyEventHandler; timer.Start(); } public void MyEventHandler(object sender, EventArgs e) { tbxTime.Text = DateTime.Now.ToString("yyyy/MM/dd HH:m:ss"); }