internal static void StartSchedule(bool initial = true) { var rand = new Random(Environment.TickCount); // first startup -> 36 seconds later var next = initial ? 0.01 : 3 + 6 * rand.NextDouble(); Observable .Timer(TimeSpan.FromHours(next)) .Subscribe(async _ => { if (await CheckPrepareUpdate(App.Version)) { if (_isUpdateNotified) { return; } _isUpdateNotified = true; var option = new TaskDialogOptions { Title = SubsystemResources.UpdateAvailableTitle, MainIcon = VistaTaskDialogIcon.Information, MainInstruction = SubsystemResources.UpdateAvailableInst, Content = SubsystemResources.UpdateAvailableContent, CustomButtons = new[] { SubsystemResources.UpdateAvailableButtonImmediate, SubsystemResources.UpdateAvailableButtonLater }, Callback = (dialog, args, data) => { if (args.Notification == VistaTaskDialogNotification.ButtonClicked && args.ButtonIndex == 0) { // update immediately StartUpdate(App.Version); } return(false); } }; MainWindowModel.ShowTaskDialog(option); } else { StartSchedule(false); } }); }
internal static void StartSchedule(bool initial = true) { var rand = new Random(Environment.TickCount); // first startup -> 36 seconds later var next = initial ? 0.01 : 3 + 6 * rand.NextDouble(); Observable .Timer(TimeSpan.FromHours(next)) .Subscribe(async _ => { if (await CheckPrepareUpdate(App.Version)) { if (_isUpdateNotified) return; _isUpdateNotified = true; var option = new TaskDialogOptions { Title = SubsystemResources.UpdateAvailableTitle, MainIcon = VistaTaskDialogIcon.Information, MainInstruction = SubsystemResources.UpdateAvailableInst, Content = SubsystemResources.UpdateAvailableContent, CustomButtons = new[] { SubsystemResources.UpdateAvailableButtonImmediate, SubsystemResources.UpdateAvailableButtonLater }, Callback = (dialog, args, data) => { if (args.Notification == VistaTaskDialogNotification.ButtonClicked && args.ButtonIndex == 0) { // update immediately StartUpdate(App.Version); } return false; } }; MainWindowModel.ShowTaskDialog(option); } else { StartSchedule(false); } }); }