//Timer控件/ System.Timers.Timer 不能用于WPF中。在WPF中,定时器为 DispatcherTimer。
//位于using System.Windows.Threading;
private DispatcherTimer timer;
//Window1_Loaded 窗体加载
public Window1()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window1_Loaded);
}
void Window1_Loaded(object sender, RoutedEventArgs e)
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += timer1_Tick;
timer.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
//(你的定时处理)
}
WPF无Timer控件&替代方法
最新推荐文章于 2024-05-23 13:34:30 发布