BlueSky.Window1.Window_Closing C# (CSharp) Method

Window_Closing() private method

private Window_Closing ( object sender, System e ) : void
sender object
e System
return void
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)///15Jan2013
        {
            try
            {
                MainWindow mwindow = LifetimeService.Instance.Container.Resolve<MainWindow>();//28Jan2013
                mwindow.Activate();
                if (mwindow.OwnedWindows.Count > 1)//if any child window exists for which mwindow is owner. count 1, app-window is already open.
                {
                    System.Windows.Forms.DialogResult dresult = ExitAppMessaageBox();//19feb2013
                    if (dresult != System.Windows.Forms.DialogResult.Yes)//save & dont close
                    {
                        e.Cancel = true;
                        return;
                    }
                    #region CLose Output Windows and then Close Syntax Eiditor
                    //// Close output window and synedtr window /// 05Feb2013
                    OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve<IOutputWindowContainer>()) as OutputWindowContainer;
                    SyntaxEditorWindow sewindow = LifetimeService.Instance.Container.Resolve<SyntaxEditorWindow>();

                    // First collect window names
                    string[] outwinnames = new string[owc.Count];
                    int i = 0;
                    foreach (KeyValuePair<String, IOutputWindow> item in owc.AllOutputWindows)
                    {
                        outwinnames[i] = item.Key;
                        i++;
                    }
                    //close each output window one by one.
                    foreach (string winname in outwinnames)
                    {
                        (owc.GetOuputWindow(winname) as Window).Close();//invoke close {Closing then Closed }
                    }

                    //now close Syntax Editor window
                    sewindow.SynEdtForceClose = true;//This line should not appear in any other place. Forcefully closing Syn Edtr.
                    sewindow.Close();
                    if (owc.Count > 0 || sewindow != null && !sewindow.SynEdtForceClose)// if any of the output window is open
                    {
                        e.Cancel = true; // abort closing.
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                logService.WriteToLogLevel("Error while closing:" + ex.Message, LogLevelEnum.Error);
            }
        }