I'm trying to show a new window if certain conditions are met, which is checked periodically using a System.Timers.Timer
.
I am very new to WPF but from what I've read from my previous question, dispatchtimers use the UI thread and are suitable for UI components, whereas the System.Timers.Timer event runs on a threadpool thread. I had previously accomplished this using my dispatchtimer, but this caused my program to stop responding when trying to exit.
Realizing that the error message: "The calling thread must be STA, because many UI components require this."
is probably referring to the fact that I can't open a new window using my System.Timers.Timer, I tried doing the following:
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();
}
This results in the same error message. Do I need to use a different timer type?