예제 #1
0
        public IList <ApplicationUninstallerEntry> GetUninstallerEntries(
            ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            var results = new List <ApplicationUninstallerEntry>();

            if (Environment.OSVersion.Version < WindowsTools.Windows7)
            {
                return(results);
            }

            Exception error = null;
            var       t     = new Thread(() =>
            {
                try
                {
                    results.AddRange(WmiQueries.GetWindowsFeatures()
                                     .Where(x => x.Enabled)
                                     .Select(WindowsFeatureToUninstallerEntry));
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            });

            t.Start();

            t.Join(TimeSpan.FromSeconds(40));

            if (error != null)
            {
                throw new IOException("Error while collecting Windows Features. If Windows Update is running wait until it finishes and try again. If the error persists try restarting your computer. In case nothing helps, read the KB957310 article.", error);
            }
            if (t.IsAlive)
            {
                t.Abort();
                throw new TimeoutException("WMI query has hung while collecting Windows Features, try restarting your computer. If the error persists read the KB957310 article.");
            }

            return(results);
        }
        public IEnumerable <ApplicationUninstallerEntry> GetUninstallerEntries(
            ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            if (Environment.OSVersion.Version < WindowsTools.Windows7)
            {
                return(Enumerable.Empty <ApplicationUninstallerEntry>());
            }

            Exception error = null;
            var       applicationUninstallers = new List <ApplicationUninstallerEntry>();
            var       t = new Thread(() =>
            {
                try
                {
                    applicationUninstallers.AddRange(WmiQueries.GetWindowsFeatures()
                                                     .Where(x => x.Enabled)
                                                     .Select(WindowsFeatureToUninstallerEntry));
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            });

            t.Start();

            t.Join(TimeSpan.FromSeconds(40));

            if (error != null)
            {
                throw new IOException("Error while collecting Windows Features, try restarting your computer. If the error persists read the KB957310 article.", error);
            }
            if (t.IsAlive)
            {
                t.Abort();
                throw new TimeoutException("WMI query has hung while collecting Windows Features, try restarting your computer. If the error persists read the KB957310 article.");
            }

            return(applicationUninstallers);
        }