wpf定时关闭弹窗

定时关闭窗口

public MainWindow()
{
StartUpGif startUpGif = new StartUpGif();
StartCloseTimer();
startUpGif.ShowDialog();
}

private void StartCloseTimer()
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(7); // 7秒
timer.Tick += TimerTick;
timer.Start();
}
private void TimerTick(object sender, EventArgs e)
{
DispatcherTimer timer = (DispatcherTimer)sender;
timer.Stop();
timer.Tick -= TimerTick; // 取消注册
startUpGif.Close();
}

posted @ 2022-11-03 14:09  谷玥  阅读(151)  评论(0)    收藏  举报