private void CancelFirmwareUpdate() { firmwareUpdateBackgroundTaskRegistration.Unregister(true); firmwareUpdateBackgroundTaskRegistration = null; // We are canceling the task, so we are no longer updating. If the task is registered but never run, // the cancel completion is never called isUpdatingFirmware = false; }
private void CancelSyncWithDevice() { if (isSyncing) { backgroundSyncTaskRegistration.Unregister(true); backgroundSyncTaskRegistration = null; // We are canceling the task, so we are no longer syncing. If the task is registered but never run, // the cancel completion is never called isSyncing = false; } }
private async void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { try { args.CheckResult(); if (ApplicationData.Current.LocalSettings.Values.ContainsKey("TaskCancelationReason")) { string cancelationReason = (string)ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"]; Error = cancelationReason; } } catch (Exception ex) { Error = "Exception" + ex.Message; } #warning unregisters the background task if (null != saferAccelerometerRegistrationManual) { saferAccelerometerRegistrationManual.Unregister(false); saferAccelerometerRegistrationManual = null; } }); }
//</SnippetRegisterBackgroundTask> //<SnippetLaunchBackgroundTask> private async void LaunchBackgroundTask() { var success = true; if (mediaProcessingTrigger != null) { MediaProcessingTriggerResult activationResult; activationResult = await mediaProcessingTrigger.RequestAsync(); switch (activationResult) { case MediaProcessingTriggerResult.Allowed: // Task starting successfully break; case MediaProcessingTriggerResult.CurrentlyRunning: // Already Triggered case MediaProcessingTriggerResult.DisabledByPolicy: // Disabled by system policy case MediaProcessingTriggerResult.UnknownError: // All other failures success = false; break; } if (!success) { // Unregister the media processing trigger background task taskRegistration.Unregister(true); } } }
async private void activePush_Toggled(object sender, RoutedEventArgs e) { Jeedom.RequestViewModel.Instance.UpdateNotificationChannel(); BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); PushNotificationTrigger trigger = new PushNotificationTrigger(); taskBuilder.SetTrigger(trigger); // Background tasks must live in separate DLL, and be included in the package manifest // Also, make sure that your main application project includes a reference to this DLL taskBuilder.TaskEntryPoint = "Notification.NotificationActionBackgroundTask"; taskBuilder.Name = "NotificationBackgroundTask"; BackgroundTaskRegistration task = null; try { task = taskBuilder.Register(); task.Completed += OnCompleted; } catch (Exception ex) { if (null != task) { task.Unregister(true); task = null; } } }
private async Task LaunchMediaTranscodeBackgroundTaskAsync() { bool success = true; if (ProcessingTrigger != null) { MediaProcessingTriggerResult ActivationResult = await ProcessingTrigger.RequestAsync(); switch (ActivationResult) { case MediaProcessingTriggerResult.Allowed: break; case MediaProcessingTriggerResult.CurrentlyRunning: case MediaProcessingTriggerResult.DisabledByPolicy: case MediaProcessingTriggerResult.UnknownError: success = false; break; } if (!success) { TaskRegistration.Unregister(true); USBControl.ThisPage.Notification.Show("转码无法启动:" + Enum.GetName(typeof(MediaProcessingTriggerResult), ActivationResult)); } } }
public static bool UnRegister() { try { BackgroundTaskRegistration task = null; // Check for existing registrations of this background task. foreach (var cur in BackgroundTaskRegistration.AllTasks) { if (cur.Value.Name == taskName) { // The task is already registered. task = (BackgroundTaskRegistration)(cur.Value); break; } } if (task != null) { task.Unregister(false); } return(true); } catch { return(false); } }
void UnregisterTask() { if (taskRegistration != null) { taskRegistration.Unregister(true); taskRegistration = null; } }
public static void UnregisterTask() { if (IsTaskRegistered()) { _current.Unregister(true); _current = null; } }
/// <summary> /// This is the click handler for the 'Disable' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ScenarioDisable(object sender, RoutedEventArgs e) { Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged); ScenarioEnableButton.IsEnabled = true; ScenarioDisableButton.IsEnabled = false; _refreshTimer.Stop(); if (null != _deviceUseBackgroundTaskRegistration) { // Cancel and unregister the background task from the current app session. _deviceUseBackgroundTaskRegistration.Unregister(true); _deviceUseBackgroundTaskRegistration = null; } else { // Cancel and unregister the background task from the previous app session. FindAndCancelExistingBackgroundTask(); } rootPage.NotifyUser("Background task was canceled", NotifyType.StatusMessage); }
private void ToggleTask_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch t = (ToggleSwitch)e.OriginalSource; BackgroundTaskRegistration bk = CheckExistTask(taskName); if (t.IsOn & bk == null) { SetBackgroundTask(timePiker.Time.TotalMinutes); } else if (!t.IsOn & bk != null) { bk.Unregister(true); } }
private async void StoptrackingButton_Click(object sender, RoutedEventArgs e) { TrackLocationButton.IsEnabled = true; StoptrackingButton.IsEnabled = false; deviceUseTask.Unregister(true); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; if (localSettings.Values.ContainsKey("endTime") == true) { object tmp = null; localSettings.Values.TryGetValue("endTime", out tmp); endTime = Convert.ToDateTime(tmp.ToString()); System.Diagnostics.Debug.WriteLine("endTime Time " + endTime.ToString()); duration = endTime - startTime; System.Diagnostics.Debug.WriteLine("Duration " + duration.TotalMinutes); } ///// if (localSettings.Values.ContainsKey("dist") == true) { object tmp = null; localSettings.Values.TryGetValue("dist", out tmp); double dist = (double)tmp; System.Diagnostics.Debug.WriteLine("FINAL Dist : " + dist); /// PARSE /// var trailObject = new ParseObject("Trail"); trailObject["distance"] = dist; trailObject["duration"] = duration.TotalMinutes; trailObject["userId"] = username; await trailObject.SaveAsync(); progressRing.IsActive = false; } }
/// <summary> /// If there is any uncached task in glucoseService, we register new one. /// </summary> /// <param name="e">Existing Link Loss Task /// This is task is only registered through Proximity Monitor</param> private GattDeviceService RetrieveLinkLossService(BackgroundTaskRegistration existingLinkLossTask) { GattDeviceService gattService = null; KeyValuePair <GattDeviceService, BackgroundTaskRegistration> cachedTask; if (LinkLossService.LinkLossServiceTaskRegistrations.TryGetValue(existingLinkLossTask.Name, out cachedTask)) { LinkLossService.WriteAlertLevelCharacteristicAsync(AlertLevelEnum.HighAlert); this.DeviceName = cachedTask.Key.Device.Name; gattService = cachedTask.Key; } else { existingLinkLossTask.Unregister(true); DeviceName = DEFAULT_DEVICE; } return(gattService); }
private async void TaskRegistration_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { TaskRegistration.Completed -= TaskRegistration_Completed; sender.Unregister(false); if (ApplicationData.Current.LocalSettings.Values["MediaTranscodeStatus"] is string ExcuteStatus) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (ExcuteStatus == "Success") { USBControl.ThisPage.Notification.Show("转码已成功完成", 10000); } else { USBControl.ThisPage.Notification.Show("转码失败:" + ExcuteStatus, 10000); } }); } }
public void OnClosing() { InPage = false; taskRegistration?.Unregister(true); taskRegistration = null; }
public async Task StartBackgroundTask(Initiator InitiatedBy) { /* PebbleConnector _pc = PebbleConnector.GetInstance(); * int Handler = await _pc.Connect(-1); * * return;*/ var result = await BackgroundExecutionManager.RequestAccessAsync(); if (result == BackgroundAccessStatus.Denied) { return; } PebbleConnector.SetBackgroundTaskRunningStatus(InitiatedBy); if (!await IsBackgroundTaskRunning()) { backgroundSyncTaskRegistration = FindSyncTask(); while (backgroundSyncTaskRegistration != null) { backgroundSyncTaskRegistration.Unregister(true); backgroundSyncTaskRegistration = FindSyncTask(); } //if (backgroundSyncTaskRegistration == null) // { syncBackgroundTaskTrigger = new DeviceUseTrigger(); // Create background task to write var backgroundTaskBuilder = new BackgroundTaskBuilder(); backgroundTaskBuilder.Name = Constants.BackgroundCommunicationTaskName; backgroundTaskBuilder.TaskEntryPoint = Constants.BackgroundCommunicationTaskEntry; backgroundTaskBuilder.SetTrigger(syncBackgroundTaskTrigger); backgroundSyncTaskRegistration = backgroundTaskBuilder.Register(); // } try { PebbleDevice _AssociatedDevice = PebbleDevice.LoadAssociatedDevice(); if (_AssociatedDevice != null) { var _device = await BluetoothDevice.FromIdAsync(_AssociatedDevice.ServiceId); //var device = (await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(new Guid(Constants.PebbleGuid))))).FirstOrDefault(y => y.Name.ToLower().Contains("pebble")); if (_device == null) { throw new OperationCanceledException("Is bluetooth enabled and the Pebble Time paired?"); } //DeviceTriggerResult x = await syncBackgroundTaskTrigger.RequestAsync(device.Id); var abc = syncBackgroundTaskTrigger.RequestAsync(_device.DeviceId).AsTask(); var x = await abc; System.Diagnostics.Debug.WriteLine("DeviceTriggerResult: " + x.ToString()); if (x != DeviceTriggerResult.Allowed) { throw new Exception(x.ToString()); } } } catch (Exception exc) { if (exc.GetType() == typeof(System.OperationCanceledException)) { throw exc; } if (exc.GetType() != typeof(System.InvalidOperationException)) { throw new Exception("Background communication task can't be started: " + exc.Message); } throw new Exception("Unexpected error: " + exc.Message); } } }