public RestartPanel() : base(2, 3, false) { RowSpacing = 6; ColumnSpacing = 6; var btnRestart = new Button() { Label = GettextCatalog.GetString("Restart {0}", BrandingService.ApplicationName), CanFocus = true, UseUnderline = true }; Attach(btnRestart, 1, 2, 1, 2, AttachOptions.Fill, AttachOptions.Fill, 0, 0); var imageRestart = new ImageView("md-information", IconSize.Menu); Attach(imageRestart, 0, 1, 0, 1, AttachOptions.Fill, AttachOptions.Fill, 0, 0); var labelRestart = new Label(GettextCatalog.GetString("These preferences will take effect next time you start {0}", BrandingService.ApplicationName)); Attach(labelRestart, 1, 3, 0, 1, AttachOptions.Fill, AttachOptions.Fill, 0, 0); imageRestart.SetCommonAccessibilityAttributes("IDEStyleOptionsPanel.RestartImage", "", GettextCatalog.GetString("A restart is required before these changes take effect")); imageRestart.SetAccessibilityLabelRelationship(labelRestart); btnRestart.Clicked += (sender, e) => { RestartRequested?.Invoke(this, EventArgs.Empty); }; }
private void BackgroundWork() { Task.Run <bool>(() => //Here we are telling Task to run a background operation and return a bool { //this body will run in a separate thread Thread.Sleep(5000); //this represents your background work var restart = true; //whatever result the bg work yields return(restart); }).ContinueWith((task) => //task is an instance of Task from above containing the result fromm the background work { var shouldRestart = task.Result; // Result is the value you returned in the body Run body above if (shouldRestart) { RestartRequested?.Invoke(this, EventArgs.Empty); } }, TaskScheduler.FromCurrentSynchronizationContext()); //This will return on the UI thread now, no need to worry about thread boundaries }
private static void UpdateCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (!e.Cancelled) { if (e.Error == null) { RestartRequested?.Invoke(new object(), new EventArgs()); } else { AppNotifyIcon.DisplayNotificationMessage($"We were unable to update to the latest version.\nError: {e.Error.Message}"); CompletedWithoutUpdate.Invoke(new object(), new EventArgs()); } } else { CompletedWithoutUpdate?.Invoke(new object(), new EventArgs()); } }
private static void OnRestartRequested(RestartEventArgs e) { RestartRequested?.Invoke(null, e); }