Esempio n. 1
0
        /// <summary>
        /// Event handler called when the background task is completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e)
        {
            // Update the UI with progress reported by the background task
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                try
                {
                    // Rethrow any exception that occurred in the background task.
                    e.CheckResult();

                    // Update the UI with the completion status of the background task
                    // The Run method of the background task sets this status.
                    MainPage.ReportSavedStatus();

                    // Extract and display location data set by the background task if not null
                    ScenarioOutput_Latitude.Text  = MainPage.LookupSavedString("Latitude", "No data");
                    ScenarioOutput_Longitude.Text = MainPage.LookupSavedString("Longitude", "No data");
                    ScenarioOutput_Accuracy.Text  = MainPage.LookupSavedString("Accuracy", "No data");
                }
                catch (Exception ex)
                {
                    // The background task had an error
                    _rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                }
            });
        }
Esempio n. 2
0
        private void WeatherUpdateTaskOnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            try
            {
                args.CheckResult();

                WeatherCondition condition;
                Enum.TryParse(GetSetting("weather.condition"), out condition);

                double celsius;
                double.TryParse(GetSetting("weather.celsius"), out celsius);

                double fahrenheit;
                double.TryParse(GetSetting("weather.fahrenheit"), out fahrenheit);

                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Weather = new WeatherForecast()
                    {
                        Condition             = condition,
                        TemperatureCelsius    = celsius,
                        TemperatureFahrenheit = fahrenheit
                    };
                });
            }
            catch (Exception exc)
            {
                new MessageDialog(exc.Message).ShowAsync();
            }
        }
Esempio n. 3
0
        private void Taskcompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            SaveText(DateTime.Now.Ticks, "Complete", id, sender.Name);

            BackgroundMediaPlayer.Shutdown();
            deferral.Complete();
        }
Esempio n. 4
0
        private async void GeofenceTask_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            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
                        args.CheckResult();

                        var settings = ApplicationData.Current.LocalSettings;

                        // get status
                        if (settings.Values.ContainsKey("Status"))
                        {
                            Status.Text = settings.Values["Status"].ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowMessage(ex.Message);
                    }
                });
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This is the callback when background event has been handled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e)
        {
            if (sender != null)
            {
                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 the LocalSettings.
                    var settings = ApplicationData.Current.LocalSettings;

                    // get status
                    if (settings.Values.ContainsKey("Status"))
                    {
                        //_rootPage.NotifyUser(settings.Values["Status"].ToString(), NotifyType.StatusMessage);
                    }

                    //FillEventListBoxWithExistingEvents();
                }
                catch { }
            }
        }
Esempio n. 6
0
        //处理通知
        private async void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            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.
                        args.CheckResult();

                        // Update the UI with the completion status of the background task.
                        // The Run method of the background task sets the LocalSettings.
                        // var settings = ApplicationData.Current.LocalSettings;

                        // Get the status.

                        // Do your app work here.

                        showMessage("围栏过期");
                    }
                    catch (Exception ex)
                    {
                        // The background task had an error.
                        //  rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                        Debug.Write(ex.Message);
                    }
                });
            }
        }
Esempio n. 7
0
 private async void OnTaskCompleted(BackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
 {
     await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         rootPage.NotifyUser("Background task completed", NotifyType.StatusMessage);
     });
 }
        /// <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, () =>
                {
                    rootPage.NotifyUser("Task cancelled unexpectedly - reason: " + settings.Values["TaskCancelationReason"].ToString(), NotifyType.ErrorMessage);
                });
            }
            else
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    rootPage.NotifyUser("Background task completed", NotifyType.StatusMessage);
                });
            }
            try
            {
                args.CheckResult();
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
            }
            Disconnect();
        }
Esempio n. 9
0
        /// <summary>
        /// background task completion handler
        ///
        /// </summary>
        private async void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e)
        {
            // Update the UI with the completion status reported by the background task.
            // Dispatch an anonymous task to the UI thread to do the update.
            await sampleDispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                            () =>
            {
                try
                {
                    e.CheckResult();

                    // get the completion status
                    var key      = sender.TaskId.ToString() + "_type";
                    var settings = ApplicationData.Current.LocalSettings;
                    var status   = settings.Values[key].ToString();
                    if ((status == NetworkOperatorEventMessageType.TetheringOperationalStateChanged.ToString()) ||
                        (status == NetworkOperatorEventMessageType.TetheringNumberOfClientsChanged.ToString()))
                    {
                        UpdateUIWithTetheringState();
                    }
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
                }
            });
        }
        // 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);
                }
            });
        }
 void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     if (deferral != null)
     {
         deferral.Complete();
     }
 }
        /// <summary>
        /// This is the callback when background event has been handled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnCompleted(IBackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs e)
        {
            try
            {
                // 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 status text box.
                        e.CheckResult();
                    }
                    catch (Exception ex)
                    {
                        // The background task had an error
                        ShowStatus(ex.ToString());
                    }
                });

                await RestoreStateAsync();
                await AttemptDeferredCheckinsAsync();
                await LogBackgroundEventsAsync();
            }
            catch (Exception exception)
            {
                Logger.Trace(TraceLevel.Error, "Background Task: OnCompleted exception " + Logger.FormatException(exception));
            }
        }
Esempio n. 13
0
        private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
        {
            BitmapImage i = new BitmapImage();

            i.UriSource    = new Uri((string)roamingSettings.Values["wpTaskUrl"], UriKind.Absolute);
            wpImage.Source = i;
        }
Esempio n. 14
0
        /// <summary>
        /// Event handle to be raised when the background task is completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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)
                        {
                            _rootPage.NotifyUser(settings.Values["Status"].ToString(), NotifyType.StatusMessage);
                        }

                        // Extract and display location data set by the background task if not null
                        ScenarioOutput_Latitude.Text  = (settings.Values["Latitude"] == null) ? "No data" : settings.Values["Latitude"].ToString();
                        ScenarioOutput_Longitude.Text = (settings.Values["Longitude"] == null) ? "No data" : settings.Values["Longitude"].ToString();
                        ScenarioOutput_Accuracy.Text  = (settings.Values["Accuracy"] == null) ? "No data" : settings.Values["Accuracy"].ToString();
                    }
                    catch (Exception ex)
                    {
                        // The background task had an error
                        _rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                    }
                });
            }
        }
        /// <summary>
        /// This is the callback when background event has been handled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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 the LocalSettings.
                        var settings = ApplicationData.Current.LocalSettings;

                        // get status
                        if (settings.Values.ContainsKey("Status"))
                        {
                            rootPage.NotifyUser(settings.Values["Status"].ToString(), NotifyType.StatusMessage);
                        }

                        FillEventListBoxWithExistingEvents();
                    }
                    catch (Exception ex)
                    {
                        // The background task had an error
                        rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                    }
                });
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Triggered when the background task has completed.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="args">The event arguments.</param>
 private void OnTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     Dispatcher.DispatchAsync(() =>
     {
         IsSyncing = false;
     });
 }
Esempio n. 17
0
 private void OnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     var settings = Windows.Storage.ApplicationData.Current.LocalSettings;
     //var key = task.TaskId.ToString();
     //var message = settings.Values[key].ToString();
     //UpdateUI(message);
 }
Esempio n. 18
0
 private async void OnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         SyncBtn.IsEnabled = true;
     });
 }
Esempio n. 19
0
        /// <summary>
        /// Runs after the service is completed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            Task.Run(async() =>
            {
                foreach (var item in BackgroundJobs)
                {
                    var result = await item.RunAsync();

                    //Update database, because job is finished.
                    if (!result)
                    {
                        item.Dispose();
                        BackgroundJobs.Remove(item);
                        return;
                    }
                }

                if (BackgroundJobs.Count == 0)
                {
                    return;
                }

                //Repeat it.
                await _trigger.RequestAsync();
            }).Wait();
        }
Esempio n. 20
0
        private async void TaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            // Should be moved to the runtime component, but it's not possible to set a reference to Chiota
            var secureStorage = new SecureStorage();

            if (secureStorage.CheckUserStored())
            {
                var user = await secureStorage.GetUser();

                if (user != null)
                {
                    // request list is needed for information
                    var contactRequestList = await user.TangleMessenger.GetJsonMessageAsync <Contact>(user.RequestAddress, 3);

                    var contactsOnApproveAddress = await new SqLiteHelper().LoadContacts(user.PublicKeyAddress);

                    var approvedContacts =
                        contactRequestList.Intersect(contactsOnApproveAddress, new ChatAdressComparer()).ToList();

                    // currently no messages for contact request due to perfomance issues
                    foreach (var contact in approvedContacts.Where(c => !c.Rejected))
                    {
                        var encryptedMessages = await user.TangleMessenger.GetMessagesAsync(contact.ChatAddress);

                        if (encryptedMessages.Any(c => !c.Stored))
                        {
                            this.CreateNotification(contact);
                        }
                    }
                }
            }
        }
Esempio n. 21
0
 private void OnTaskComplete(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     //var taskName = sender.Name;
     //if (taskName == BackgroundDataTemplate.ResetDaylyTasksTimeTriggerName || taskName == BackgroundDataTemplate.ResetDaylyTasksSystemTriggerName) ConfigPlatform();
     //else GlobalDataService.UnregisterBackgroundTask(taskName);
     ConfigPlatform();
     RefreshUI();
 }
Esempio n. 22
0
        private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            var result   = ApplicationData.Current.LocalSettings.Values["factorial"];
            var progress = $"Результат: {result}";

            UpdateUI(progress);
            Stop();
        }
Esempio n. 23
0
 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()
         );
 }
Esempio n. 24
0
        private void TaskReg_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            var setting = Windows.Storage.ApplicationData.Current.LocalSettings;
            var key     = sender.TaskId.ToString();
            var message = setting.Values[key].ToString();

            System.Diagnostics.Debug.WriteLine(message);
        }
Esempio n. 25
0
 private async static void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     await CallUIThreadHelper.CallOnUiThreadAsync(() => new ToastContentBuilder().AddArgument("action", "viewConversation")
                                                  .AddArgument("conversationId", 9813)
                                                  .AddText("You have no internet!")
                                                  .AddText("App may not operate normally.")
                                                  .Show());
 }
 private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
 {
     var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         var msgbox = new MessageDialog("Completed?");
         var ignore = msgbox.ShowAsync();
     });
 }
        /// <summary>
        /// Suscribe to the OnCompleted method if the app needs to know a task was executed in
        /// the foreground and finished by the time the app is launched.
        /// </summary>
        private async void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
        {
            var settings = ApplicationData.Current.LocalSettings;
            var key      = task.Name.ToString();
            var message  = settings.Values[key].ToString();

            this.MainPage_Loaded(this, null);
        }
Esempio n. 28
0
 private async void OnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     // Serialize UI update to the the main UI thread.
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         ShowErrorDialog(CommonData.TaskExitReason, "BgTask exit");
     });
 }
Esempio n. 29
0
 void OnBackgroundTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
 {
     this.Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         () =>
     {
         this.RebuildListOfNotifications();
     });
 }
Esempio n. 30
0
        private void Task_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            var settings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var key      = "BackgroundTask";
            var message  = settings.Values[key].ToString();

            // Run your background task code here
            MessagingCenter.Send <object, string>(this, "UpdateLabel", message);
        }