AcManager.Tools.Helpers.WindowsHelper.RestartCurrentApplication C# (CSharp) Method

RestartCurrentApplication() private method

private RestartCurrentApplication ( ) : void
return void
        public static void RestartCurrentApplication() {
            try {
                ProcessExtension.Start(MainExecutingFile.Location,
                        Environment.GetCommandLineArgs()
                                   .Skip(1)
                                   .ApartFrom(RestartArg)
                                   .Where(x => !x.StartsWith("acmanager:", StringComparison.OrdinalIgnoreCase))
                                   .Prepend(RestartArg));
                if (Application.Current != null) {
                    Application.Current.Shutdown();
                } else {
                    Environment.Exit(0);
                }
            } catch (Exception e) {
                Logging.Warning("RestartCurrentApplication(): " + e);
            }
        }
        

Usage Example

Example #1
0
        private static async Task DownloadAndInstall(CancellationToken token)
        {
            var directory = _directory ?? MainExecutingFile.Directory;

            try {
                var data = await CmApiProvider.GetStaticDataAsync("visual_cpp", TimeSpan.FromDays(1), cancellation : token);

                if (data == null)
                {
                    ManualInstallation(null, directory);
                }
                else
                {
                    await Task.Run(() => {
                        using (var archive = ZipFile.OpenRead(data.Item1)) {
                            foreach (var file in archive.Entries)
                            {
                                var completeFileName = Path.Combine(directory, file.FullName);
                                if (file.Name == "" || File.Exists(completeFileName))
                                {
                                    continue;
                                }
                                FileUtils.EnsureFileDirectoryExists(completeFileName);
                                file.ExtractToFile(completeFileName, true);
                            }
                        }
                    });

                    FileUtils.TryToDelete(data.Item1);
                    if (ModernDialog.ShowMessage("The package is installed. Now, app needs to be restarted. Restart it now?", "The package is installed",
                                                 MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        WindowsHelper.RestartCurrentApplication();
                    }
                }
            } catch (Exception e) when(e.IsCancelled())
            {
            } catch (Exception e) {
                ManualInstallation(e, directory);
            }
        }