Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用计时器在10秒后关闭(自动隐藏)WPF窗口_C#_Wpf - Fatal编程技术网

C# 如何使用计时器在10秒后关闭(自动隐藏)WPF窗口

C# 如何使用计时器在10秒后关闭(自动隐藏)WPF窗口,c#,wpf,C#,Wpf,如何在10秒后使用C#中的计时器关闭(自动隐藏)WPF窗口?按以下方式操作: private void StartCloseTimer() { DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(10d); timer.Tick += TimerTick; timer.Start(); } private void TimerTick(objec

如何在10秒后使用C#中的计时器关闭(自动隐藏)WPF窗口?

按以下方式操作:

private void StartCloseTimer()
{
    DispatcherTimer timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromSeconds(10d);
    timer.Tick += TimerTick;
    timer.Start();
}

private void TimerTick(object sender, EventArgs e)
{
    DispatcherTimer timer = (DispatcherTimer)sender;
    timer.Stop();
    timer.Tick -= TimerTick;
    Close();
}