private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { ShellToast toast = new ShellToast(); toast.Title = "Sample Application"; toast.Content = "Background Task Complete"; toast.Show(); }
void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { if (deferral != null) { deferral.Complete(); } }
private void OnBackgroundTaskCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { UpdateLastRunTime(); }
/// <summary> /// Indicate that the background task is completed. /// </summary> void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine("MyBackgroundAudioTask " + sender.TaskId + " Completed..."); deferral.Complete(); }
/// <summary> /// Handle background task completion. /// </summary> /// <param name="task">The task that is reporting completion.</param> /// <param name="e">Arguments of the completion report.</param> private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { UpdateUI(); }
/// <summary> /// Reopen the device after the background task is done syncing. Notify the UI of how many bytes we wrote to the device. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void OnSyncWithDeviceCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { // Exception may be thrown if an error occurs during running the background task args.CheckResult(); await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(async () => { // Reopen the device once the background task is completed await EventHandlerForDevice.Current.OpenDeviceAsync(syncDeviceInformation, syncDeviceSelector); syncDeviceInformation = null; syncDeviceSelector = null; var taskCompleteStatus = (String)ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskStatus]; if (taskCompleteStatus == SyncBackgroundTaskInformation.TaskCompleted) { UInt32 totalBytesWritten = (UInt32)ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskResult]; rootPage.NotifyUser("Sync: Wrote " + totalBytesWritten.ToString() + " bytes to the device", NotifyType.StatusMessage); } else if (taskCompleteStatus == SyncBackgroundTaskInformation.TaskCanceled) { rootPage.NotifyUser("Syncing was canceled", NotifyType.StatusMessage); } // Remove all local setting values ApplicationData.Current.LocalSettings.Values.Clear(); isSyncing = false; UpdateButtonStates(); })); // Unregister the background task and let the remaining task finish until completion if (backgroundSyncTaskRegistration != null) { backgroundSyncTaskRegistration.Unregister(false); } }
private async void OnTaskCompleted(BackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Background task completed", NotifyType.StatusMessage); }); }
/// <summary> /// This is the event handler for background task completion. /// </summary> /// <param name="task">The task that is reporting completion.</param> /// <param name="args">The completion report arguments.</param> private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { string status = "Completed"; try { args.CheckResult(); } catch (Exception e) { status = e.Message; } UpdateUIAsync(status); }
async private void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e) { if (sender != null) { // Update the UI with progress reported by the background task await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { try { // If the background task threw an exception, display the exception in // the error text box. e.CheckResult(); // Update the UI with the completion status of the background task // The Run method of the background task sets this status. var settings = ApplicationData.Current.LocalSettings; if (settings.Values["Status"] != null) { rootPage.NotifyUser(settings.Values["Status"].ToString(), NotifyType.StatusMessage); } // Extract and display Latitude if (settings.Values["Latitude"] != null) { ScenarioOutput_Latitude.Text = settings.Values["Latitude"].ToString(); } else { ScenarioOutput_Latitude.Text = "No data"; } // Extract and display Longitude if (settings.Values["Longitude"] != null) { ScenarioOutput_Longitude.Text = settings.Values["Longitude"].ToString(); } else { ScenarioOutput_Longitude.Text = "No data"; } // Extract and display Accuracy if (settings.Values["Accuracy"] != null) { ScenarioOutput_Accuracy.Text = settings.Values["Accuracy"].ToString(); } else { ScenarioOutput_Accuracy.Text = "No data"; } } catch (Exception ex) { // The background task had an error rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage); } }); } }
private void OnCompleted( IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e ) { if( sender != null ) { // If the background task threw an exception, display the exception in // the error text box. e.CheckResult(); LocationChanged(); // if( settings.Values[ "Longitude" ] != null ) // if( settings.Values[ "Accuracy" ] != null ) } }
private async void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e) { if (sender != null) { // Update the UI with progress reported by the background task await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { try { // If the background task threw an exception, display the exception in the // error text box. e.CheckResult(); // Update the UI with the completion status of the background task The Run // method of the background task sets this status. var settings = ApplicationData.Current.LocalSettings; if (settings.Values["Status"] != null) { Status.Text = settings.Values["Status"].ToString(); } // Extract and display location data set by the background task if not null MobilePosition_Latitude.Text = (settings.Values["Latitude"] == null) ? "No data" : settings.Values["Latitude"].ToString(); MobilePosition_Longitude.Text = (settings.Values["Longitude"] == null) ? "No data" : settings.Values["Longitude"].ToString(); MobilePosition_Accuracy.Text = (settings.Values["Accuracy"] == null) ? "No data" : settings.Values["Accuracy"].ToString(); } catch (Exception ex) { // The background task had an error Status.Text = ex.ToString(); } }); } }
private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { BackgroundMediaPlayer.Shutdown(); _deferral.Complete(); }
/// <summary> /// Reopen the device after the background task is done syncing. Notify the UI of how many bytes we wrote to the device. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void OnSyncWithDeviceCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { isSyncing = false; // Exception may be thrown if an error occurs during running the background task args.CheckResult(); await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(async () => { // Reopen the device once the background task is completed // Don't attempt to reconnect if the device failed to connect var isDeviceSuccessfullyConnected = await EventHandlerForDevice.Current.OpenDeviceAsync(syncDeviceInformation, syncDeviceSelector); if (!isDeviceSuccessfullyConnected) { EventHandlerForDevice.Current.IsEnabledAutoReconnect = false; } syncDeviceInformation = null; syncDeviceSelector = null; // Since we are navigating away, don't touch the UI; we don't care what the output/result of the background task is if (!navigatedAway) { var taskCompleteStatus = (String)ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskStatus]; if (taskCompleteStatus == SyncBackgroundTaskInformation.TaskCompleted) { UInt32 totalBytesWritten = (UInt32)ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskResult]; // Set the progress bar to be completely filled in case the progress was not updated (this can happen if the app is suspended) SyncProgressBar.Value = 100; rootPage.NotifyUser("Sync: Wrote " + totalBytesWritten.ToString() + " bytes to the device", NotifyType.StatusMessage); } else if (taskCompleteStatus == SyncBackgroundTaskInformation.TaskCanceled) { // Reset the progress bar in case the progress was not updated (this can happen if the app is suspended) SyncProgressBar.Value = 0; rootPage.NotifyUser("Syncing was canceled", NotifyType.StatusMessage); } UpdateButtonStates(); } // Remove all local setting values ApplicationData.Current.LocalSettings.Values.Clear(); })); // Unregister the background task and let the remaining task finish until completion if (backgroundSyncTaskRegistration != null) { backgroundSyncTaskRegistration.Unregister(false); } }
private async void Mytask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { // Background task has completed - refresh our data await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async () => await LoadRuntimeDataAsync() ); }
private void RegistrationCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { ApplicationDataContainer container = ApplicationData.Current.LocalSettings; try { var content = container.Values["RawMessage"].ToString(); if (content != null) { ToastMessage message = JsonConvert.DeserializeObject<ToastMessage>(content); ToastHelper.DisplayTextToast(ToastTemplateType.ToastImageAndText01, message.FromId, message.Content, message.FromPicture); } } catch (Exception ex) { ex.ToString(); } }
/// <summary> /// Called when background task defferal is completed. This can happen for a number of reasons (both expected and unexpected). /// IF this is expected, we'll notify the user. If it's not, we'll show that this is an error. Finally, clean up the connection by calling Disconnect(). /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void OnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { var settings = ApplicationData.Current.LocalSettings; if (settings.Values.ContainsKey("TaskCancelationReason")) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { statusTextBlock.Text = "ERROR: Task cancelled unexpectedly - reason: " + settings.Values["TaskCancelationReason"].ToString(); }); } else { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { statusTextBlock.Text = "STATUS: Background task completed"; }); } try { args.CheckResult(); } catch (Exception ex) { throw; //rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); } Disconnect(); }
void liveTileUpdater_BackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { DispatchUpdateUI(); }
/// <summary> /// Background task completion handler. When authenticating through the foreground app, this triggers the authentication flow if the app is currently running. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public async void OnBackgroundTaskCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e) { // Update the UI with progress reported by the background task. await coreDispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { try { if ((sender != null) && (e != null)) { // If the background task threw an exception, display the exception in the error text box. e.CheckResult(); // Update the UI with the completion status of the background task // The Run method of the background task sets this status. if (sender.Name == BackgroundTaskName) { rootPage.NotifyUser("Background task completed", NotifyType.StatusMessage); // Signal callback for foreground authentication if (!ConfigStore.AuthenticateThroughBackgroundTask && ForegroundAuthenticationCallback != null) { ForegroundAuthenticationCallback(this, null); } } } } catch (Exception ex) { rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage); } })); }
/// <summary> /// Handle background task completion. /// </summary> /// <param name="task">The task that is reporting completion.</param> /// <param name="e">Arguments of the completion report.</param> private async void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; Object profile = localSettings.Values["InternetProfile"]; Object adapter = localSettings.Values["NetworkAdapterId"]; Object hasNewConnectionCost = localSettings.Values["HasNewConnectionCost"]; Object hasNewDomainConnectivityLevel = localSettings.Values["HasNewDomainConnectivityLevel"]; Object hasNewHostNameList = localSettings.Values["HasNewHostNameList"]; Object hasNewInternetConnectionProfile = localSettings.Values["HasNewInternetConnectionProfile"]; Object hasNewNetworkConnectivityLevel = localSettings.Values["HasNewNetworkConnectivityLevel"]; await NetworkStatusWithInternetPresentDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { string outputText = string.Empty; if ((profile != null) && (adapter != null)) { //If internet profile has changed, display the new internet profile if ((string.Equals(profile.ToString(), internetProfile, StringComparison.Ordinal) == false) || (string.Equals(adapter.ToString(), networkAdapter, StringComparison.Ordinal) == false)) { internetProfile = profile.ToString(); networkAdapter = adapter.ToString(); outputText += "Internet Profile changed\n" + "=================\n" + "Current Internet Profile : " + internetProfile + "\n\n"; if (hasNewConnectionCost != null) { outputText += hasNewConnectionCost.ToString() + "\n"; } if (hasNewDomainConnectivityLevel != null) { outputText += hasNewDomainConnectivityLevel.ToString() + "\n"; } if (hasNewHostNameList != null) { outputText += hasNewHostNameList.ToString() + "\n"; } if (hasNewInternetConnectionProfile != null) { outputText += hasNewInternetConnectionProfile.ToString() + "\n"; } if (hasNewNetworkConnectivityLevel != null) { outputText += hasNewNetworkConnectivityLevel.ToString() + "\n"; } rootPage.NotifyUser(outputText, NotifyType.StatusMessage); } } }); }
private void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { args.CheckResult(); // TODO: What kind of errors does this report? Debug.WriteLine(sender); // BackgroundTaskRegistration string instanceIdString = args.InstanceId.ToString(); if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(instanceIdString)) { // This task didn't schedule a download. return; } Guid transferGuid = (Guid)ApplicationData.Current.LocalSettings.Values[instanceIdString]; Debug.WriteLine("Background task completed! Last download was {0}", transferGuid); }
/// <summary> /// This is the background task completion handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e) { // Dispatch to the UI thread to display the output. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // An exception may be thrown if an error occurs in the background task. try { e.CheckResult(); if (ApplicationData.Current.LocalSettings.Values.ContainsKey("TaskCancelationReason")) { string cancelationReason = (string)ApplicationData.Current.LocalSettings.Values["TaskCancelationReason"]; rootPage.NotifyUser("Background task was stopped, reason: " + cancelationReason, NotifyType.StatusMessage); } } catch (Exception ex) { rootPage.NotifyUser("Exception in background task: " + ex.Message, NotifyType.ErrorMessage); } _refreshTimer.Stop(); }); // Unregister the background task and let the remaining task finish until completion. if (null != _deviceUseBackgroundTaskRegistration) { _deviceUseBackgroundTaskRegistration.Unregister(false); _deviceUseBackgroundTaskRegistration = null; } }
private async void RegTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { string json = await readStringFromLocalFile("parking.json"); ParkingResult[] result = JsonConvert.DeserializeObject<ParkingResult[]>(json); foreach(var parking in result) { if (parking.parkingStatus == null) continue; points.Add(new PointOfInterest() { DisplayName = parking.name, FreePlaces = parking.parkingStatus.availableCapacity, Location = new Geopoint(new BasicGeoposition() { Latitude = parking.latitude, Longitude = parking.longitude }), ParkingResult = parking }); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, RefreshUI); }
private static void BgTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { LogMessage("BgTask Completed", NotifyType.StatusMessage); }
private void OnBackGroundTaskCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { Debug.WriteLine("refreshing the screen"); Dispatcher.RunAsync(CoreDispatcherPriority.High, RefreshScreen); }
/// <summary> /// Handle background task completion. /// </summary> /// <param name="task">The task that is reporting completion.</param> /// <param name="e">Arguments of the completion report.</param> private async void OnBackgroundTaskCompleted(BackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs eventArgs) { // We get the status changed processed by the background task if (ApplicationData.Current.LocalSettings.Values.Keys.Contains(taskName)) { string backgroundMessage = (string) ApplicationData.Current.LocalSettings.Values[taskName]; // Serialize UI update to the main UI thread await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Display the status change PublisherStatusBlock.Text = backgroundMessage; }); } }
// Handle background task completion event. private async void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e) { // Update the UI with the complrtion status reported by the background task. // Dispatch an anonymous task to the UI thread to do the update. await sampleDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { try { if ((sender != null) && (e != null)) { // this method throws if the event is reporting an error e.CheckResult(); // Update the UI with the background task's completion status. // The task stores status in the application data settings indexed by the task ID. var key = sender.TaskId.ToString(); var settings = ApplicationData.Current.LocalSettings; BackgroundTaskStatus.Text = settings.Values[key].ToString(); } } catch (Exception ex) { rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage); } }); }
/// <summary> /// Handle background task completion. /// </summary> /// <param name="task">The task that is reporting completion.</param> /// <param name="e">Arguments of the completion report.</param> private async void OnBackgroundTaskCompleted(BackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs eventArgs) { // We get the advertisement(s) processed by the background task if (ApplicationData.Current.LocalSettings.Values.Keys.Contains(taskName)) { string backgroundMessage = (string) ApplicationData.Current.LocalSettings.Values[taskName]; // Serialize UI update to the main UI thread await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Display these information on the list ReceivedAdvertisementListBox.Items.Add(backgroundMessage); }); } }
/// <summary> /// Indicate that the background task is completed. /// </summary> private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { logger.LogMessage($"Background Audio Task {sender.TaskId} Completed..."); Dispose(); }
/// <summary> /// Event fires after background task completes. /// </summary> /// <param name="task"></param> /// <param name="args"></param> private void OnCortanaMakeTaskCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args) { Windows.Storage.ApplicationDataContainer settings = Windows.Storage.ApplicationData.Current.LocalSettings; string key = task.TaskId.ToString(); string message = settings.Values[key].ToString(); }
private void Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args) { defferal.Complete(); }