Exemple #1
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                // Dispose window first, as it needs the cache to clear out its notification.
                if (m_mainWnd != null)
                {
                    m_mainWnd.Dispose();
                }
                if (m_cache != null)
                {
                    UndoResult ures = 0;
                    while (m_cache.CanUndo)
                    {
                        m_cache.Undo(out ures);
                        if (ures == UndoResult.kuresFailed || ures == UndoResult.kuresError)
                        {
                            Assert.Fail("ures should not be == " + ures.ToString());
                        }
                    }
                    m_cache.Dispose();                     // Yes, since the window isn't supposed to do it.
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_cache   = null;
            m_mainWnd = null;
            m_scr     = null;
            // Restore prompt setting
            Options.ShowEmptyParagraphPromptsSetting = m_saveShowPrompts;             // Options is some kind of Registry gizmo.

            base.Dispose(disposing);
        }