-2

In my WPF application, I have to show some windows on UI thread and some on separate thread. I can access all windows running on UI thread using System.Windows.Application.Current.Windows, but unable to find windows that are running on separate thread.

Can any one knows how can i achieve this ?

Thanks

  • 1
    How would you run a window in another thread? Do you mean another process? – juharr Mar 10 '16 at 12:45
  • 1
    Windows only run on the main UI thread. If they're running on another thread, you have a problem. – rory.ap Mar 10 '16 at 12:47
  • 1
    I have created windows on separate thread, using http://stackoverflow.com/questions/1111369/how-do-i-create-and-show-wpf-windows-on-separate-threads – Mohammad Muhiuddin Mar 10 '16 at 13:06
  • WPF Recipes in C# 2008 by Sam Noble, Sam Bourton has a chapter on this, along with all the bookkeeping that goes along with it. But if you are just starting out, you'd need a very good reason for creating windows on another thread. If you want more responsive windows, do slower tasks using async await or another threading model. – Dean Mar 10 '16 at 13:53

1 Answers1

3

System.Windows.Application.Current.Windows only gives you Windows that where created on the UIThread not on WorkerThread. From the MSDN:

A Window reference is automatically added to Windows as soon as a window is instantiated on the user interface (UI) thread; windows that are created by worker threads are not added.

I guess you will have to do the book keeping on your own. For instance by using a static list of windows. Keep in mind that you need to guard that against concurrent access and you need to remove those windows when they get closed.

Kolja
  • 2,307
  • 15
  • 23