I have a WPF application in which a thread checks some value. In certain cases, I show a pop-up Window
in order to display a message. When I create this pop-up window in the thread, an exception is thrown by the pop-up window's constructor:
"The calling thread must be STA, because many UI components require this."
How do I resolve this error?
This is my code for creating the pop-up window:
// using System.Threading;
// using System.Windows.Threading;
Thread Messagethread = new Thread(new ThreadStart(delegate()
{
DispatcherOperation DispacherOP =
frmMassenger.Dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate()
{
frmMassenger.Show();
}));
}));
Messagethread.Start();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…