private async void UIElement_OnTapped(object sender, TappedRoutedEventArgs e) { if (LightButton.IsChecked == true) { ApplicationData.Current.LocalSettings.Values["AppTheme"] = (int)ElementTheme.Light; } else { ApplicationData.Current.LocalSettings.Values["AppTheme"] = (int)ElementTheme.Dark; } MessageDialog msgDialog = new MessageDialog("Changing the theme requires restarting the application, would you like to restart now?"); UICommand cancelCommand = new UICommand("Cancel"); UICommand restartCommand = new UICommand("Restart"); msgDialog.Commands.Add(restartCommand); msgDialog.Commands.Add(cancelCommand); IUICommand command = await msgDialog.ShowAsync(); if (command.Equals(restartCommand)) { AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(""); } }
private async void RequestRestartAsync_OnClick(object sender, RoutedEventArgs e) { Logger logger = LogFactory.GetLogger(nameof(RequestRestartAsync_OnClick)); await Task.Delay(5000); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { try { AppRestartFailureReason arfr = await CoreApplication.RequestRestartAsync(""); if (arfr == AppRestartFailureReason.NotInForeground || arfr == AppRestartFailureReason.Other) { logger.Log($"AppRestartFailureReason {arfr}"); } } catch (Exception ex) { logger.Log($"AppRestartFailureReason Exception {ex.Message}"); } logger.Flush(); }); ; }
private async void ThemePicker_SelectionChanged(object sender, SelectionChangedEventArgs e) { ContentDialog areYouSure = new ContentDialog { Title = "Are You Sure?", Content = "The application will restart upon changing this setting. Select Yes to continue, Cancel to go back.", PrimaryButtonText = "Cancel", CloseButtonText = "Yes" }; ContentDialogResult result = await areYouSure.ShowAsync(); if (result != ContentDialogResult.Primary) { switch (ThemePicker.SelectedItem?.ToString().Split(new[] { ": " }, StringSplitOptions.None).Last()) { case "Light": Windows.Storage.ApplicationData.Current.LocalSettings.Values["userThemeSetting"] = 0; break; case "Dark": Windows.Storage.ApplicationData.Current.LocalSettings.Values["userThemeSetting"] = 1; break; default: Windows.Storage.ApplicationData.Current.LocalSettings.Values["userThemeSetting"] = null; break; } AppRestartFailureReason result2 = await CoreApplication.RequestRestartAsync("test"); } else { Frame.Navigate(typeof(SettingsView), empID); } }
async private void DoRestartRequest() { bool isValidPayload = false; string payload = restartArgs.Text; if (!string.IsNullOrEmpty(payload)) { foreach (ImageViewModel imageItem in imageListView.Items) { if (imageItem.Name == payload) { isValidPayload = true; break; } } } if (isValidPayload) { AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(payload); if (result == AppRestartFailureReason.NotInForeground || result == AppRestartFailureReason.RestartPending || result == AppRestartFailureReason.Other) { Debug.WriteLine("RequestRestartAsync failed: {0}", result); } } }
public async Task RestartAsync() { AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(launchArguments); if (result == AppRestartFailureReason.NotInForeground || result == AppRestartFailureReason.Other) { Application.Current.Exit(); } }
private async void StoreSettingsClickCommandAsync() { await StoreTimersService.SaveTimerInSettingsAsync(WorkTimerSettingsKey, SettingsWorkTimer); await StoreTimersService.SaveTimerInSettingsAsync(ShortBreakTimerSettingsKey, SettingsShortBreakTimer); await StoreTimersService.SaveTimerInSettingsAsync(LongBreakTimerSettingsKey, SettingsLongBreakTimer); AppRestartFailureReason result = await CoreApplication.RequestRestartAsync("-fastInit -level 1 -foo"); }
private async Task <bool> RestartAppAsync(string appArgs = "") { AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(appArgs); // When successful, execution stops above and the app closes. // Anything below gets executed when the request failed. Debug.WriteLine($"{this.GetType()}: RestartAppAsync: Result was {result}"); return(false); }
// アプリの再起動 // How to Restart your App Programmatically - Windows Developer Blog (2017/07/28) // https://blogs.windows.com/buildingapps/2017/07/28/restart-app-programmatically/ private async void RestartButton_Click(object sender, RoutedEventArgs e) { RestartButton.IsEnabled = false; RestartDescriptionText.Text = ""; using (var newSession = new ExtendedExecutionSession()) { newSession.Reason = ExtendedExecutionReason.Unspecified; await newSession.RequestExtensionAsync(); // ↑最小化されたときにサスペンドされるのを延期する(バックグラウンド実行) // ※バッテリー駆動時は最大10分まで await Task.Delay(3000); // 動作確認のため、しばらく遅らせる // 再起動を要求する string param = App.RestartParamHeader + ParamText.Text; AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(param); switch (result) { case AppRestartFailureReason.RestartPending: // 正常に再起動処理が始まった RestartDescriptionText.Text = "再起動中…";//この表示は見えない break; case AppRestartFailureReason.NotInForeground: // 失敗 RestartDescriptionText.Text = "再起動失敗:アプリがフォアグラウンドになっていません。"; break; //case AppRestartFailureReason.InvalidUser: // // 失敗(引数にユーザーを指定した場合に発生しうる) // RestartDescriptionText.Text // = "AppRestartFailureReason.InvalidUser"; // break; case AppRestartFailureReason.Other: // 失敗 RestartDescriptionText.Text = "再起動失敗:予期しない理由です。"; break; #if DEBUG default: throw new ArgumentOutOfRangeException($"想定外のAppRestartFailureReason({result})"); #endif } } RestartButton.IsEnabled = true; }
private static async Task ChangeHostAsync(string host, string passwordHashSalt) { // Log out the user account from the current moebooru site YandeClient.SignOut(); // Clear all wallpaper/lockscreen records as they are only identified with postId using (var db = new AppDbContext()) { db.Database.ExecuteSqlCommand($"delete from {nameof(AppDbContext.WallpaperRecords)}; delete from {nameof(AppDbContext.LockScreenRecords)}"); } // Change the site settings YandeSettings.Current.Host = host; YandeSettings.Current.PasswordHashSalt = passwordHashSalt; // Close the app AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(""); }
async void DisplayNext() { if (_currentIndex == _screens.Length) { _currentIndex = 0; try { _screens = await _sm.GetScreensAsync(_url, _feedId, _passcode); } catch (Exception ex) { _errorCount += 1; await Task.Delay(TimeSpan.FromSeconds(20)); if (_errorCount > 1) { // kill the app AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(""); if (result == AppRestartFailureReason.NotInForeground || result == AppRestartFailureReason.RestartPending || result == AppRestartFailureReason.Other) { GetScreens(); } } else { DisplayNext(); } } } Screen s = _screens[_currentIndex]; _t = null; if (s.sign_type == "hide") { _currentIndex = _currentIndex + 1; DisplayNext(); } else { if (s.sign_type == "web") { view_web.Visibility = Windows.UI.Xaml.Visibility.Visible; view_image.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_text.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_media.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_web.Visibility = Windows.UI.Xaml.Visibility.Visible; view_web.Navigate(new Uri(s.uri)); } if (s.sign_type == "video") { view_web.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_image.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_text.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_media.Visibility = Windows.UI.Xaml.Visibility.Visible; view_media.Source = new Uri(s.uri); } else if (s.sign_type == "image") { view_image.Visibility = Windows.UI.Xaml.Visibility.Visible; view_web.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_text.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_media.Visibility = Windows.UI.Xaml.Visibility.Collapsed; BitmapImage imageSource = new BitmapImage(new Uri(s.uri)); view_image.Width = imageSource.DecodePixelHeight = (int)this.ActualWidth; view_image.Source = imageSource; } else if (s.sign_type == "text") { view_text.Visibility = Windows.UI.Xaml.Visibility.Visible; view_web.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_image.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_media.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_text.Document.SetText(Windows.UI.Text.TextSetOptions.None, s.sign_text); } else if (s.sign_type == "tweet") { view_web.Visibility = Windows.UI.Xaml.Visibility.Visible; view_image.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_text.Visibility = Windows.UI.Xaml.Visibility.Collapsed; view_media.Visibility = Windows.UI.Xaml.Visibility.Collapsed; try { _t = await _sm.GetTweetAsync(s.uri); view_web.Source = new Uri("ms-appx-web:///Tweet.html"); } catch (Exception ex) { _errorCount += 1; DisplayNext(); } } _currentTimer = Convert.ToInt32(s.duration); _disTimer.Interval = new TimeSpan(0, 0, _currentTimer); _disTimer.Start(); _currentIndex = _currentIndex + 1; } }
private async void btnRestart_Click(object sender, RoutedEventArgs e) { AppRestartFailureReason result = await CoreApplication.RequestRestartAsync(txtParams.Text); }
private async void Button_Click(object sender, RoutedEventArgs e) { try { PackageManager manager = new PackageManager(); var test = manager.FindPackageForUser(string.Empty, Package.Current.Id.FullName); var updateAvailable = await test.CheckUpdateAvailabilityAsync(); var info = test.GetAppInstallerInfo(); var dialog = new MessageDialog($"Update ? : {updateAvailable.Availability}, Uri = {info?.Uri}"); await dialog.ShowAsync(); if (updateAvailable.Availability == PackageUpdateAvailability.Available || updateAvailable.Availability == PackageUpdateAvailability.Required) { //Try to update the app dialog = new MessageDialog($"Starting update"); await dialog.ShowAsync(); var result = await manager.AddPackageByAppInstallerFileAsync(info.Uri, AddPackageByAppInstallerOptions.ForceTargetAppShutdown, manager.GetDefaultPackageVolume()); //var result = await manager.UpdatePackageAsync(info.Uri, null, DeploymentOptions.ForceApplicationShutdown); dialog = new MessageDialog($"Finished update ´: {result.ErrorText}, {result.ExtendedErrorCode}"); await dialog.ShowAsync(); if (!string.IsNullOrEmpty(result.ErrorText)) { dialog = new MessageDialog($"Error: {result.ExtendedErrorCode}, {result.ErrorText}"); await dialog.ShowAsync(); } else { AppRestartFailureReason restartResult = await CoreApplication.RequestRestartAsync(string.Empty); if (restartResult == AppRestartFailureReason.NotInForeground || restartResult == AppRestartFailureReason.RestartPending || restartResult == AppRestartFailureReason.Other) { dialog = new MessageDialog($"Restart: {restartResult}"); await dialog.ShowAsync(); } } } if (updateAvailable.Availability == PackageUpdateAvailability.Error) { dialog = new MessageDialog($"Error: {updateAvailable.ExtendedError}"); await dialog.ShowAsync(); } } catch (Exception ex) { var dialog = new MessageDialog($"exception: {ex}, InnerException {ex.InnerException}"); await dialog.ShowAsync(); } }