从所有线程获取所有窗口 [英] Get all windows from all threads

查看:150
本文介绍了从所有线程获取所有窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中启动一些线程,例如

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

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?

推荐答案

您不应在应用程序主线程以外的任何线程上创建窗口.相反,请在主应用程序线程上创建所有窗口,并使用其他线程(例如任务并行库)异步工作,以使主应用程序的线程(以及UI)保持响应状态.

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.

这篇关于从所有线程获取所有窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆