Dispose() public method

Disposes of resources used by this instance.
public Dispose ( ) : void
return void
        private void CreateRefreshAndPruneApplications(IEnumerable <ApplicationElement> elements)
        {
            List <ApplicationProcess> pruning = this.applications
                                                .Where(a => !elements.Any(e => a.Path.Equals(e.ApplicationPath, StringComparison.OrdinalIgnoreCase)))
                                                .ToList();

            List <ApplicationProcess> existing = this.applications
                                                 .Where(a => elements.Any(e => a.Path.Equals(e.ApplicationPath, StringComparison.OrdinalIgnoreCase)))
                                                 .ToList();

            List <ApplicationElement> creating = elements
                                                 .Where(e => !this.applications.Any(a => e.ApplicationPath.Equals(a.Path, StringComparison.OrdinalIgnoreCase)))
                                                 .ToList();

            // Prune removed applications.
            foreach (ApplicationProcess application in pruning)
            {
                application.Exited -= new EventHandler(this.ApplicationExited);
                application.Stop(true);
                application.Dispose();
            }

            // Stop and re-initialize changed applications.
            foreach (ApplicationProcess application in existing)
            {
                ApplicationElement element = elements.Where(e => application.Path.Equals(e.ApplicationPath, StringComparison.OrdinalIgnoreCase)).First();

                if (!(application.ConfigPath ?? string.Empty).Equals(element.ApplicationConfigPath, StringComparison.OrdinalIgnoreCase) ||
                    application.Force32Bit != element.Force32Bit ||
                    application.FrameworkVersion != element.Framework)
                {
                    if (this.SetApplicationProperties(application, element))
                    {
                        application.Stop(true);
                    }
                }
            }

            // Create added applications.
            foreach (ApplicationElement element in creating)
            {
                ApplicationProcess application = null;

                try
                {
                    try
                    {
                        application = new ApplicationProcess(this.logger, element.ApplicationPath, this.exePath);
                    }
                    catch (ArgumentException ex)
                    {
                        this.logger.Error(
                            new ConfigurationErrorsException(
                                "The value for 'path' contains invalid characters.",
                                ex,
                                element.ElementInformation.Source,
                                element.ElementInformation.LineNumber));
                    }

                    if (application != null)
                    {
                        application.Exited += new EventHandler(this.ApplicationExited);

                        if (this.SetApplicationProperties(application, element))
                        {
                            existing.Add(application);
                        }
                    }
                }
                catch
                {
                    if (application != null)
                    {
                        application.Dispose();
                    }

                    throw;
                }
            }

            lock (this.locker)
            {
                this.applications = existing;
            }
        }
        private void CreateRefreshAndPruneApplications(IEnumerable<ApplicationElement> elements)
        {
            List<ApplicationProcess> pruning = this.applications
                .Where(a => !elements.Any(e => a.Path.Equals(e.ApplicationPath, StringComparison.OrdinalIgnoreCase)))
                .ToList();

            List<ApplicationProcess> existing = this.applications
                .Where(a => elements.Any(e => a.Path.Equals(e.ApplicationPath, StringComparison.OrdinalIgnoreCase)))
                .ToList();

            List<ApplicationElement> creating = elements
                .Where(e => !this.applications.Any(a => e.ApplicationPath.Equals(a.Path, StringComparison.OrdinalIgnoreCase)))
                .ToList();

            // Prune removed applications.
            foreach (ApplicationProcess application in pruning)
            {
                application.Exited -= new EventHandler(this.ApplicationExited);
                application.Stop(true);
                application.Dispose();
            }

            // Stop and re-initialize changed applications.
            foreach (ApplicationProcess application in existing)
            {
                ApplicationElement element = elements.Where(e => application.Path.Equals(e.ApplicationPath, StringComparison.OrdinalIgnoreCase)).First();

                if (!(application.ConfigPath ?? string.Empty).Equals(element.ApplicationConfigPath, StringComparison.OrdinalIgnoreCase)
                    || application.Force32Bit != element.Force32Bit
                    || application.FrameworkVersion != element.Framework)
                {
                    if (this.SetApplicationProperties(application, element))
                    {
                        application.Stop(true);
                    }
                }
            }

            // Create added applications.
            foreach (ApplicationElement element in creating)
            {
                ApplicationProcess application = null;

                try
                {
                    try
                    {
                        application = new ApplicationProcess(this.logger, element.ApplicationPath, this.exePath);
                    }
                    catch (ArgumentException ex)
                    {
                        this.logger.Error(
                            new ConfigurationErrorsException(
                                "The value for 'path' contains invalid characters.",
                                ex,
                                element.ElementInformation.Source,
                                element.ElementInformation.LineNumber));
                    }

                    if (application != null)
                    {
                        application.Exited += new EventHandler(this.ApplicationExited);

                        if (this.SetApplicationProperties(application, element))
                        {
                            existing.Add(application);
                        }
                    }
                }
                catch
                {
                    if (application != null)
                    {
                        application.Dispose();
                    }

                    throw;
                }
            }

            lock (this.locker)
            {
                this.applications = existing;
            }
        }