I had the same problem. We have a great silverlight app with OOB.
For some reason, m_ClosingEvent was launched some time after the launch. I could not find the cause of this problem, but I think that it may have something to do with us, changing the root visual or all the child windows that we show.
I am using the ApplicationWrapper class.
public class ApplicationWrapper : IApplicationWrapper { public void Initialize() { HookCloseEvent(true); } private void HookCloseEvent(bool hook) { if (hook && IsRunningOutOfBrowser) { Application.Current.MainWindow.Closing += OnClosing; } else { if (IsRunningOutOfBrowser) { Application.Current.MainWindow.Closing -= OnClosing; } } } private void OnClosing(object sender, ClosingEventArgs e) { InvokeClosing(e); } ... etc.. }
And the InvokeClosing method has never been called. But when I changed it to
public class ApplicationWrapper : IApplicationWrapper { private Window _mainWindow; public void Initialize() { if(IsRunningOutOfBrowser) { _mainWindow = Application.Current.MainWindow; } HookCloseEvent(true); } private void HookCloseEvent(bool hook) { if (hook && IsRunningOutOfBrowser) { _mainWindow.Closing += OnClosing; } else { if (IsRunningOutOfBrowser) { _mainWindow.Closing -= OnClosing; } } } private void OnClosing(object sender, ClosingEventArgs e) { InvokeClosing(e); } ... etc... }
m_ClosingEvent is not nullified.
So, just try to save the โinitialโ MainWindow in the field and see if this solves your problem.
Truls clauss
source share