示例#1
0
        private void TerminateInternal()
        {
            // If we fail, we at least should advertise that we're now dead
            Interlocked.Exchange(ref _terminated, _true);

            EventsTerminated?.Invoke(this, EventArgs.Empty);
            EventsTerminated = delegate { };
            var projectIds = _components.Keys.ToArray();

            foreach (var projectid in projectIds)
            {
                UnregisterProjectHandlers(projectid);
            }

            if (_projects.IsWrappingNullReference)
            {
                return;
            }

            _projects.ProjectActivated -= ProjectActivatedHandler;
            _projects.ProjectRenamed   -= ProjectRenamedHandler;
            _projects.ProjectRemoved   -= ProjectRemovedHandler;
            _projects.ProjectAdded     -= ProjectAddedHandler;
            _projects.DetachEvents();
            _projects.Dispose();
        }
示例#2
0
        /// <remarks>
        /// This is a not a true implementation of IDisposable pattern
        /// because the method is made private and is available only
        /// via the static method <see cref="Terminate"/> to provide
        /// a single point of entry for disposing the singleton class
        /// </remarks>
        private void Dispose(bool disposing)
        {
            if (!_disposed && _projects != null)
            {
                EventsTerminated?.Invoke(this, EventArgs.Empty);

                var projectIds = _components.Keys.ToArray();
                foreach (var projectid in projectIds)
                {
                    UnregisterComponents(projectid);
                }

                _projects.ProjectActivated -= ProjectActivatedHandler;
                _projects.ProjectRenamed   -= ProjectRenamedHandler;
                _projects.ProjectRemoved   -= ProjectRemovedHandler;
                _projects.ProjectAdded     -= ProjectAddedHandler;
                _projects.DetachEvents();
                _projects.Dispose();

                _disposed = true;
            }
        }