2

I work on an application which has a main window and some TextBlocks on it. Once user clicks a TextBlock, a new window is created and display the data chart related to that TextBlock. I create such new chart Wndow on a different thread, as following:

 private void xTB_MouseDown(object sender, MouseButtonEventArgs e) { Thread _displayChartThread = new Thread(() => { Window w = new Window() w.Closed += (sender2, e2) =>w.Dispatcher.InvokeShutdown(); w.Show(); System.Windows.Threading.Dispatcher.Run(); }); _displayChartThread.SetApartmentState(ApartmentState.STA); _displayChartThread.IsBackground = true; _displayChartThread.Start(); } 

The problem is, when you have multiple chart windows open, and you close the main window, the chart windows are still open and not get destroyed. I can see that the chart windows have no knowledge of the main window being their Owner, and I can't set their Owner property to main window in the thread in which chart window is created.

Any ideas on how to handle this? I mean once main window is closed, all the chart window (created in different threads) are also closed.

Thanks in advance.

1
  • Did you try to set the Parent of the new created window to the main window? Commented Oct 10, 2011 at 12:56

1 Answer 1

1

You can keep references to the child windows in the main window. When the main window is closed, you can close all the child windows ( invoke CLose using the childWindow.Dispatcher )

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.