Yes, I had seen it was removed after making that change. I only removed the one line where you are setting the object to null.
The problem is the structure of your code in Terminated. You are using many InvokeAsync statements and then set an object they all use to null before they run. When using InvokeAsync, that is not happening now but will happen when it can in the future so setting the chartWindow to null prevents the individual async events from working.
I would suggest that you remove the individual invokes you have used and group all of those commands into one event like the following:
else if (State == State.Terminated) { if (chartWindow != null) { ChartControl.Dispatcher.InvokeAsync((Action)(() => { if (exampleButton != null) { chartWindow.MainMenu.Remove(exampleButton); exampleButton = null; } //below for toolbar button if (btnRuler != null) { chartWindow.MainMenu.Remove(btnRuler); btnRuler = null; } ...... chartWindow.MainTabControl.SelectionChanged -= MySelectionChangedHandler; chartWindow = null; })); } }
I look forward to being of further assistance.
Leave a comment: