예제 #1
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();

                // If the process has started, all three disposable objects will be valid
                // I would just call OnStop, but the code analysis tool doesn't look inside
                // it and thinks the members aren't being Disposed.
                if (Processors.Count > 0)
                {
                    // Clean up the directory watcher and crash processor threads
                    foreach (var Processor in Processors)
                    {
                        // Non-blocking cancel request
                        Processor.RequestStop();
                    }
                    foreach (var Processor in Processors)
                    {
                        // Blocking stop and dispose
                        Processor.Dispose();
                    }
                    Processors.Clear();

                    Watcher.Dispose();
                    Watcher = null;

                    StatusReporter.Dispose();
                    StatusReporter = null;

                    Slack.Dispose();
                    Slack = null;

                    // Flush the log to disk
                    Log.Dispose();
                    Log = null;
                }
            }
            base.Dispose(disposing);
        }