/* * /// <summary> * /// Periodically check if there's a new message and if there is, send it over the socket * /// </summary> * /// <param name="timer"></param> * * private async void PeriodicTimerCallback(ThreadPoolTimer timer) * { * if (!_cancelRequested) * if (!_cancelRequested) * { * string message; * try * { * message = SendMessages.Dequeue(); * } * catch (Exception) * { * return; * } * * try * { * // Make sure that the connection is still up and there is a message to send * if (_socket != null) * { * if (message == null) return; * _writer.WriteString(message); * await _writer.StoreAsync(); * } * else * { * _cancelReason = BackgroundTaskCancellationReason.ConditionLoss; * _deferral.Complete(); * } * } * catch (Exception ex) * { * LocalSettings.Values["TaskCancelationReason"] = ex.Message; * _deferral.Complete(); * } * } * else * { * // Timer clean up * _periodicTimer.Cancel(); * // * // Write to LocalSettings to indicate that this background task ran. * // * LocalSettings.Values["TaskCancelationReason"] = _cancelReason.ToString(); * } * }*/ private async void TimerCallback(object state) { if (!_cancelRequested) { string message; try { message = SendMessages.Dequeue(); } catch (Exception) { return; } try { // Make sure that the connection is still up and there is a message to send if (_socket != null) { if (message == null) { return; } _writer.WriteString(message); await _writer.StoreAsync(); Logger.Logger.Info("Message Sent"); } else { _cancelReason = BackgroundTaskCancellationReason.ConditionLoss; _deferral.Complete(); Logger.Logger.Info("Message was not sent. Socket is down!"); } } catch (Exception ex) { LocalSettings.Values["TaskCancelationReason"] = ex.Message; _deferral.Complete(); Logger.Logger.Error(ex.Message, ex); } } else { // Timer clean up _timer.Dispose(); // // Write to LocalSettings to indicate that this background task ran. // LocalSettings.Values["TaskCancelationReason"] = _cancelReason.ToString(); Logger.Logger.Info("TimerCallback" + _cancelReason.ToString()); } }
/// <summary> /// Invoked as a cancellation callback when the background task is /// cancelled for any reason, for a graceful exit. /// /// We don't care about the particular reason (i.e. the app was /// aborted, system shutdown, etc.) so we don't need to do different /// behavior depending on the reason. /// </summary> /// <param name="sender">The background task instance.</param> /// <param name="reason">The reason for thread cancellation.</param> private void TaskInstance_Canceled( IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason ) { // // Step 1 // Stop the GATT server // StopGattServer(); // // Step 2 // Stop device enumeration if it is still in progress when this // background app is canceled // if (enumerator != null) { enumerator.StopSupportedDeviceEnumerator(); enumerator.EnumerationCompleted -= WatchForEnumerationCompletion; } switch (reason) { case BackgroundTaskCancellationReason.Abort: //app unregistered background task (amoung other reasons). Debug.WriteLine("Background task aborted. Reason: " + reason.ToString()); break; case BackgroundTaskCancellationReason.Terminating: //system shutdown Debug.WriteLine("Background task terminating. Reason: " + reason.ToString()); break; case BackgroundTaskCancellationReason.ConditionLoss: Debug.WriteLine("Background task cancelled because of condition loss. Reason: " + reason.ToString()); break; case BackgroundTaskCancellationReason.SystemPolicy: Debug.WriteLine("Background task cancelled because of system policy. Reason: " + reason.ToString()); break; } // // Step 2 // Complete the deferral // mainDeferral.Complete(); }
private async void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { _log.LogInformation("StartupTask terminated for reason " + reason.ToString()); await Task.Delay(5000); //a few reasons that you may be interested in. switch (reason) { case BackgroundTaskCancellationReason.Abort: //app unregistered background task (amoung other reasons). break; case BackgroundTaskCancellationReason.Terminating: //system shutdown break; case BackgroundTaskCancellationReason.ConditionLoss: break; case BackgroundTaskCancellationReason.SystemPolicy: break; case BackgroundTaskCancellationReason.LoggingOff: break; } _deferral.Complete(); }
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { BackgroundTaskDeferral deferral = sender.GetDeferral(); ShowToast("Background task canceled: " + reason.ToString()); deferral.Complete(); }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); SettingsEditor.InitSettings(); taskInstance.Canceled += this.OnCanceled; using (var writer = new SyslogWriter(Facility.local0, "WakeOnDoor")) { var opened = await writer.OpenAsync(); if (opened) { twatcher = new TweLiteWatcher(); try { await twatcher.WatchAsync(); await writer.Warning(CancelReason.ToString()); } catch (TaskCanceledException e) { await writer.Warning(e.Message); } twatcher.Dispose(); } } deferral.Complete(); }
/// <summary> /// Handles background task cancellation. /// </summary> /// <param name="sender">The background task instance being cancelled.</param> /// <param name="reason">The cancellation reason.</param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { var settings = ApplicationData.Current.LocalSettings; Debug.WriteLine("Background " + sender.Task.Name + " Cancel Requested..."); settings.Values["TaskStatus"] = reason.ToString() + " at " + DateTime.Now.ToString("u"); }
public void OnBackgroundTaskCanceled(IBackgroundTaskInstance instance, string name, BackgroundTaskCancellationReason reason) { var canceled = true; var strreason = reason.ToString(); switch (name) { case "ControlChannelReset": PushEvent(WindowsType.ControlChannelReset, canceled, strreason); break; case "InternetAvailable": PushEvent(WindowsType.InternetAvailable, canceled, strreason); break; case "InternetNotAvailable": PushEvent(WindowsType.InternetNotAvailable, canceled, strreason); break; case "ServicingComplete": PushEvent(WindowsType.ServicingComplete, canceled, strreason); break; case "SessionConnected": PushEvent(WindowsType.SessionConnected, canceled, strreason); break; case "UserAway": PushEvent(WindowsType.UserAway, canceled, strreason); break; case "UserPresent": PushEvent(WindowsType.UserPresent, canceled, strreason); break; case "LockScreenApplicationAdded": PushEvent(WindowsType.LockScreenApplicationAdded, canceled, strreason); break; case "LockScreenApplicationRemoved": PushEvent(WindowsType.LockScreenApplicationRemoved, canceled, strreason); break; case "TimeZoneChange": PushEvent(WindowsType.TimeZoneChange, canceled, strreason); break; } }
// // Simulate the background task activity. // private void PeriodicTimerCallback(ThreadPoolTimer timer) { if ((_cancelRequested == false) && (_progress < 100)) { _progress += 10; _taskInstance.Progress = _progress; } else { _periodicTimer.Cancel(); var key = _taskInstance.Task.Name; // // Record that this background task ran. // String taskStatus = (_progress < 100) ? "Canceled with reason: " + _cancelReason.ToString() : "Completed"; BackgroundTaskSample.TaskStatuses[key] = taskStatus; Debug.WriteLine("Background " + _taskInstance.Task.Name + taskStatus); // // Indicate that the background task has completed. // _deferral.Complete(); } }
private void PeriodicTimerCallback(ThreadPoolTimer timer) { if ((_cancelRequested == false) && (_progress < 100)) { _progress += 10; _taskInstance.Progress = _progress; } else { _periodicTimer.Cancel(); var key = _taskInstance.Task.Name; // // Record that this background task ran. // String taskStatus = (_progress < 100) ? "Canceled with reason: " + _cancelReason.ToString() : "Completed"; var settings = ApplicationData.Current.LocalSettings; settings.Values[key] = taskStatus; Debug.WriteLine("Background " + _taskInstance.Task.Name + settings.Values[key]); _deferral.Complete(); } }
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { var properties = new Dictionary<string, string>(); properties.Add("Reason", reason.ToString()); StartupTask.WriteTelemetryEvent("AppServicesBackgroundTask_Canceled", properties); serviceDeferral.Complete(); }
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { Debug.WriteLine($"Canceled: {reason.ToString()}"); if (serviceDeferral != null) { serviceDeferral.Complete(); } }
/// <summary> /// Called when the background task is canceled by the app or by the system. /// </summary> /// <param name="sender"></param> /// <param name="reason"></param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"] = reason.ToString(); ApplicationData.Current.LocalSettings.Values["SampleCount"] = _sampleCount; ApplicationData.Current.LocalSettings.Values["IsBackgroundTaskActive"] = false; // Complete the background task (this raises the OnCompleted event on the corresponding BackgroundTaskRegistration). _deferral.Complete(); }
public async Task Close(BackgroundTaskCancellationReason reason) { await SendMessageAsync("Bot geht aus."); await _log.InfoAsync($"Task wurde beendet, weil: {reason.ToString()}"); _CheckServerStateTimer.Cancel(); _ctSrc.Cancel(); _ctSrc.Dispose(); }
private void LogTaskError(BackgroundTaskCancellationReason reason) { var settingsValues = ApplicationData.Current.LocalSettings.Values; var taskActivity = new ApplicationDataCompositeValue { ["LastRun"] = DateTime.Now.ToLocalTime().ToString(), ["Exception"] = reason.ToString() }; settingsValues[_TileTaskActivity] = taskActivity; }
private async void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { var properties = new Dictionary<string, string>(); properties.Add("Reason", reason.ToString()); WriteTelemetryEvent("App_Shutdown", properties); await s_radioManager.Dispose(); deferral.Complete(); }
private void OnCanceled(IBackgroundTaskInstance taskInstance, BackgroundTaskCancellationReason reason) { cancelReason = reason; cancelRequested = true; ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"] = cancelReason.ToString(); ApplicationData.Current.LocalSettings.Values["IsBackgroundTaskActive"] = false; ApplicationData.Current.LocalSettings.Values["ReceivedMessage"] = ""; // Complete the background task (this raises the OnCompleted event on the corresponding BackgroundTaskRegistration). deferral.Complete(); }
private void PeriodicTimerCallback(ThreadPoolTimer timer) { if (_cancelRequested == false) { // get exclusive use of port _adapter.beginExclusive(true); // open a path to the temp device _path.open(); // check if present if (_owc.Present) { // read the temp device byte[] state = _tc.readDevice(); _tc.doTemperatureConvert(state); state = _tc.readDevice(); Debug.WriteLine("Temperature of " + _address + " is " + _tc.getTemperature(state) + " C"); } else { Debug.WriteLine("Device " + _address + " not present so stopping thread"); } // close the path to the device _path.close(); // release exclusive use of port _adapter.endExclusive(); } else { _periodicTimer.Cancel(); var settings = ApplicationData.Current.LocalSettings; var key = _taskInstance.Task.Name; // // Write to LocalSettings to indicate that this background task ran. // settings.Values[key] = "Canceled with reason: " + _cancelReason.ToString(); Debug.WriteLine("Background " + _taskInstance.Task.Name + settings.Values[key]); // // Indicate that the background task has completed. // _deferral.Complete(); } }
private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { // Indicate that the background task is canceled. _cancelRequested = true; ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; ApplicationDataCompositeValue stats = new ApplicationDataCompositeValue(); stats["date"] = DateTime.Now; stats["error"] = reason.ToString(); localSettings.Values["wallerror"] = stats; }
private void OnCanceled(IBackgroundTaskInstance taskInstance, BackgroundTaskCancellationReason reason) { _cancelReason = reason; _cancelRequested = true; LocalSettings.Values["TaskCancelationReason"] = _cancelReason.ToString(); LocalSettings.Values["IsBackgroundTaskActive"] = false; LocalSettings.Values["ReceivedMessage"] = ""; ToastNotificationManager.History.Clear(); // Complete the background task (this raises the OnCompleted event on the corresponding BackgroundTaskRegistration). _deferral.Complete(); Logger.Logger.Info("Rfcomm Server OnCanceled Event: " + _cancelReason); }
private void OnTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { var details = sender.TriggerDetails as AppServiceTriggerDetails; if (_connections.ContainsKey(details.AppServiceConnection)) { Logging.Instance.LogMessage($@"closing connection reason: {reason.ToString()}"); _connections[details.AppServiceConnection].Complete(); } else { Logging.Instance.LogMessage($@"closing unkown connection", LoggingLevel.Critical); } }
/// <summary> /// Called when the background task is canceled by the app or by the system. /// </summary> /// <param name="sender"></param> /// <param name="reason"></param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"] = reason.ToString(); ApplicationData.Current.LocalSettings.Values["SampleCount"] = SampleCount; ApplicationData.Current.LocalSettings.Values["IsBackgroundTaskActive"] = false; if (null != Accelerometer) { Accelerometer.ReadingChanged -= new TypedEventHandler <Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged); Accelerometer.ReportInterval = 0; } // Complete the background task (this raises the OnCompleted event on the corresponding BackgroundTaskRegistration). Deferral.Complete(); }
/// <summary> /// Called when the background task is canceled by the app or by the system. /// </summary> /// <param name="sender"></param> /// <param name="reason"></param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"] = reason.ToString(); ApplicationData.Current.LocalSettings.Values["SampleCount"] = SampleCount; ApplicationData.Current.LocalSettings.Values["IsBackgroundTaskActive"] = false; if (null != Accelerometer) { Accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged); Accelerometer.ReportInterval = 0; } // Complete the background task (this raises the OnCompleted event on the corresponding BackgroundTaskRegistration). Deferral.Complete(); }
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { _AppTriggerDeferral?.Complete(); _SyncDeferral?.Complete(); _ToastDeferral?.Complete(); _ExExecSession.Revoked -= ExExecSession_Revoked; _ExExecSession.Dispose(); _ExExecSession = null; ToastHelper.ShowMessage($"{sender.Task.Name} has been canceled", reason.ToString()); //switch (sender.Task.Name) //{ // case "SyncNotifications": // case "SyncNotificationsApp": // _SyncDeferral?.Complete(); // _SyncAppDeferral?.Complete(); // break; // case "ToastNotificationBackgroundTask": // _ToastActionDeferral?.Complete(); // break; //} }
private void HandleTaskInstanceCanceled(IBackgroundTaskInstance taskInstance, BackgroundTaskCancellationReason reason) { PlayQueueManager.Current.Disconnect(); TileUpdateManager.CreateTileUpdaterForApplication("App").Clear(); Logger.Current.Log(new CallerInfo(), LogLevel.Info, "AudioPlayer Background Task Completed id:{0} reason:{1}", taskInstance.Task.TaskId, reason.ToString()); ApplicationSettings.PutSettingsValue(ApplicationSettings.IS_BACKGROUND_PROCESS_ACTIVE, false); if (ApplicationSettings.GetSettingsValue <bool>(ApplicationSettings.IS_FOREGROUND_PROCESS_ACTIVE, false)) { PlayQueueManager.Current.SendMessageToForeground(PlayQueueConstantBGMessageId.BackgroundEnded); } backgroundTaskState = BackgroundTaskState.Stopped; PlayQueueManager.Current.TrackChanged -= HandlePlayQueueTrackChanged; BackgroundMediaPlayer.Current.CurrentStateChanged -= HandleBackgroundMediaPlayerCurrentStateChanged; taskInstance.Task.Completed -= HandleTaskInstanceTaskCompleted; taskInstance.Canceled -= HandleTaskInstanceCanceled; BackgroundMediaPlayer.Shutdown(); Logger.Current.Flush(); backgroundTaskDefferal.Complete(); }
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { _logger.LogInfo(reason.ToString()); _readCancellationTokenSource.Cancel(); _runTask = false; }
// Handles background task cancellation. private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { // Indicate that the background task is canceled. _cancelRequested = true; _cancelReason = reason; Toast.ShowToast("Location Background Task has been canceled because of " + reason.ToString()); geolocator.PositionChanged -= OnPositionChanged; }
/// <summary> /// Handles background task cancellation. /// </summary> /// <param name="sender">The background task instance being cancelled.</param> /// <param name="reason">The cancellation reason.</param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { var settings = ApplicationData.Current.LocalSettings; settings.Values["TaskStatus"] = reason.ToString() + " at " + DateTime.Now.ToString("u"); }
private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { //TODO: I SHOULD CANCEL THE BG TASKS HERE _logger.Warning($"{sender.Task.Name} cancel requested... Cancel reason = {reason.ToString()}"); }
private void OnCanceled(IBackgroundTaskInstance taskInstance, BackgroundTaskCancellationReason reason) { CommonData.TaskExitReason = reason.ToString(); deferral.Complete(); }
// Handles background task cancellation. private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { // Indicate that the background task is canceled. Toast.ShowToast("Geofence Background Task has been canceled because of " + reason.ToString()); }
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { Debug.WriteLine("StartupTask.TaskInstance_Canceled() - {0}", reason.ToString()); _deferal.Complete(); }
private void HandleTaskInstanceCanceled(IBackgroundTaskInstance taskInstance, BackgroundTaskCancellationReason reason) { PlayQueueManager.Current.Disconnect(); TileUpdateManager.CreateTileUpdaterForApplication("App").Clear(); Logger.Current.Init(LogType.AudioFunction); Logger.Current.Log(new CallerInfo(), LogLevel.Info, "AudioPlayer Background Task Completed id:{0} reason:{1}", taskInstance.Task.TaskId, reason.ToString()); ApplicationSettings.PutSettingsValue(ApplicationSettings.IS_BACKGROUND_PROCESS_ACTIVE, false); if (ApplicationSettings.GetSettingsValue<bool>(ApplicationSettings.IS_FOREGROUND_PROCESS_ACTIVE, false)) { PlayQueueManager.Current.SendMessageToForeground(PlayQueueConstantBGMessageId.BackgroundEnded); } backgroundTaskState = BackgroundTaskState.Stopped; PlayQueueManager.Current.TrackChanged -= HandlePlayQueueTrackChanged; BackgroundMediaPlayer.Current.CurrentStateChanged -= HandleBackgroundMediaPlayerCurrentStateChanged; taskInstance.Task.Completed -= HandleTaskInstanceTaskCompleted; taskInstance.Canceled -= HandleTaskInstanceCanceled; BackgroundMediaPlayer.Shutdown(); Logger.Current.Flush(); backgroundTaskDefferal.Complete(); }
/// <summary> /// Standard Cancel handler for a background task /// </summary> /// <param name="sender"></param> /// <param name="reason"></param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { // // Indicates that the background task is canceled. // UtilitiesLibrary.SendToastNotification("Background Print Workflow Task " + sender.Task.Name + " received a Cancel Request, reason " + reason.ToString() + ", instance " + sender.InstanceId.ToString(), null); Task.Delay(60000); }
/// <summary> /// Periodically check if there's a new message and if there is, send it over the socket /// </summary> /// <param name="timer"></param> private async void PeriodicTimerCallback(ThreadPoolTimer timer) { if (!cancelRequested) { string message = (string)ApplicationData.Current.LocalSettings.Values["SendMessage"]; if (!string.IsNullOrEmpty(message)) { try { // Make sure that the connection is still up and there is a message to send if (socket != null) { writer.WriteUInt32((uint)message.Length); writer.WriteString(message); await writer.StoreAsync(); ApplicationData.Current.LocalSettings.Values["SendMessage"] = null; } else { cancelReason = BackgroundTaskCancellationReason.ConditionLoss; deferral.Complete(); } } catch (Exception ex) { ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"] = ex.Message; ApplicationData.Current.LocalSettings.Values["SendMessage"] = null; deferral.Complete(); } } } else { // Timer clean up periodicTimer.Cancel(); // // Write to LocalSettings to indicate that this background task ran. // ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"] = cancelReason.ToString(); } }
/// <summary> /// Behandelt den Abbruch der Hintergrundaufgabe. /// </summary> /// <param name="sender">Die Instanz der IBackgroundTask, die das Canceled Event ausgelöst hat.</param> /// <param name="reason">Der Grund für den Abbruch.</param> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { // Mache hier vorest nichts. Nur Fehler loggen. Debug.WriteLine("Abort RawNotification background task. Sender: " + sender.ToString() + ", Reason: " + reason.ToString()); }
//</SnippetProgress> //<SnippetOnCanceled> private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { Debug.WriteLine("Background " + sender.Task.Name + " Cancel Requested..." + reason.ToString()); }