Exemplo n.º 1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="LogFile"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    // This will be done regardless of whether the object is finalized or disposed.
                    if (disposing)
                    {
                        // This will be done only when the object is disposed by calling Dispose().
                        SaveSettings();

                        this.FileFull -= LogFile_FileFull;

                        if ((object)m_operationWaitHandle != null)
                        {
                            m_operationWaitHandle.Close();
                        }

                        if ((object)m_fileStream != null)
                        {
                            m_fileStream.Dispose();
                        }

                        if ((object)m_logEntryQueue != null)
                        {
                            m_logEntryQueue.ProcessException -= ProcessExceptionHandler;
                            m_logEntryQueue.Dispose();
                        }
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }