0

如果满足某些条件,我会尝试显示一个新窗口,使用System.Timers.Timer.

我对 WPF 很陌生,但从我之前的问题中了解到,调度计时器使用 UI 线程并且适用于 UI 组件,而 System.Timers.Timer 事件在线程池线程上运行。我之前使用调度计时器完成了此操作,但这导致我的程序在尝试退出时停止响应。

意识到错误消息:"The calling thread must be STA, because many UI components require this."可能是指我无法使用 System.Timers.Timer 打开新窗口这一事实,我尝试执行以下操作:

private void timer1_Tick(object sender, EventArgs e)
{
    //... other timer functions
    if(conditions are met)
    {
          ShowNewWindow();
    }

}
private static void ShowNewWindow()
{
    NewWindow nw = new NewWindow();
    nw.Show();
}

这会导致相同的错误消息。我需要使用不同的计时器类型吗?

4

0 回答 0