Get all windows from all threads

蓝咒 提交于 2019-12-11 12:25:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!