问题
I start in my application some threads like
this.Thread = new Thread(() =>
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
...
...
}));
System.Windows.Threading.Dispatcher.Run();
}) { IsBackground = true, Name = Constants.SPECIAL_UI_THREAD_NAME};
this.Thread.SetApartmentState(ApartmentState.STA);
this.Thread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
this.Thread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
this.Thread.Start();
They have all a Window which is generated and shown. Now, when I use in my Main-Thread
Application.Current.Windows
I don't get the windows of my additional threads.
How can I get all windows of all threads of my application?
回答1:
You shouldn't be creating windows on any thread other than the application's main thread. Instead, have all windows created on the main app thread and use other threads (e.g. task parallel library) to do work asynchronously such that the main application's thread (and therefore UI) remains responsive.
来源:https://stackoverflow.com/questions/10267143/get-all-windows-from-all-threads