当前位置: 首页>>代码示例>>C#>>正文


C# BackgroundTaskCompletedEventArgs.CheckResult方法代码示例

本文整理汇总了C#中Windows.ApplicationModel.Background.BackgroundTaskCompletedEventArgs.CheckResult方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundTaskCompletedEventArgs.CheckResult方法的具体用法?C# BackgroundTaskCompletedEventArgs.CheckResult怎么用?C# BackgroundTaskCompletedEventArgs.CheckResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.ApplicationModel.Background.BackgroundTaskCompletedEventArgs的用法示例。


在下文中一共展示了BackgroundTaskCompletedEventArgs.CheckResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnBackgroundTaskCompleted

        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);
        }
开发者ID:kiewic,项目名称:Projects,代码行数:15,代码来源:App.xaml.cs

示例2: OnCompleted

        // 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);
                }
            });
        }
开发者ID:mbin,项目名称:Win81App,代码行数:28,代码来源:BackgroundTask.xaml.cs

示例3: OnCompleted

        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);
                    }
                });
            }
        }
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:59,代码来源:Scenario3_BackgroundTask.xaml.cs

示例4: OnBackgroundTaskCompleted

        /// <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);
                                          }
                                      }));
        }
开发者ID:mbin,项目名称:Win81App,代码行数:38,代码来源:ScenarioCommon.cs

示例5: GeofenceTask_Completed

        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);
                    }
                });
            }
            

        }
开发者ID:asepj,项目名称:Wp8.1CompleteReference,代码行数:30,代码来源:MainPage.xaml.cs

示例6: OnCompleted

    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 )
      }
    }
开发者ID:Georotzen,项目名称:.NET-SDK-1,代码行数:15,代码来源:Win8LocationTrackerEngine.cs

示例7: OnTaskCompleted

        public void OnTaskCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            Debug.WriteLine("BackgroundAudioRun.TaskOnCompleted() " + _id);

            try
            {
                args.CheckResult();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BackgroundAudioRun.TaskOnCompleted() " + _id + " failed: " + ex.Message);
            }

            _completionSource.TrySetResult(null);
        }
开发者ID:henricj,项目名称:phonesm,代码行数:15,代码来源:BackgroundAudioRun.cs

示例8: OnBackgroundTaskCompleted

        /// <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;
            }
        }
开发者ID:SoftwareFactoryUPC,项目名称:ProjectTemplates,代码行数:35,代码来源:Scenario1_DeviceUse.xaml.cs

示例9: OnCompleted

        /// <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);
                    }
                });
        }
开发者ID:mbin,项目名称:Win81App,代码行数:31,代码来源:StartStopTethering.xaml.cs

示例10: OnCompleted

        /// <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);
                    }
                });
            }
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:38,代码来源:Scenario5_GeofenceBackgroundTask.xaml.cs

示例11: OnCompleted

        private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs arg)
        {
            var settings = ApplicationData.Current.LocalSettings;
            var key = task.TaskId.ToString();
            var message = "Klaar met synchroniseren-" + DateTime.Now;
            UpdateUIExampleMethod(message);

            string tileXmlString = "<tile>" + "<visual>" + "<binding template='TileWideText03'>" + "<text id='1'>"
                + "</text>" + "</binding>" + "<binding template='TileSquareText04'>" + "<text id='1'>"
             + "</text>" + "</binding>" + "</visual>" + "</tile>";
            var tileXml = new Windows.Data.Xml.Dom.XmlDocument(); tileXml.LoadXml(tileXmlString);
            var tile = new Windows.UI.Notifications.TileNotification(tileXml);
            Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tile);

            try
            {
                arg.CheckResult();

            }
            catch (Exception)
            {
                message = "error";
                UpdateUIExampleMethod(message);
            }
        }
开发者ID:Nathaliev68,项目名称:Repository,代码行数:25,代码来源:StartPage.xaml.cs

示例12: OnFirmwareUpdateCompleted

        /// <summary>
        /// Print the version number
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void OnFirmwareUpdateCompleted(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(() =>
                {
                    var taskCompleteStatus = (String)ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.FirmwareUpdateBackgroundTask.TaskStatus];

                    if (taskCompleteStatus == FirmwareUpdateTaskInformation.TaskCompleted)
                    {
                        // Display firmware version after the firmware update
                        var newFirmwareVersion = (UInt32) ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.FirmwareUpdateBackgroundTask.NewFirmwareVersion];

                        var newFirmwareVersionHex = "0x" + newFirmwareVersion.ToString("X4", NumberFormatInfo.InvariantInfo);

                        UpdateNewFirmwareVersionInUI(newFirmwareVersionHex);

                        rootPage.NotifyUser("Firmware update completed", NotifyType.StatusMessage);
                    }
                    else if (taskCompleteStatus == FirmwareUpdateTaskInformation.TaskCanceled)
                    {
                        rootPage.NotifyUser("Firmware update was canceled", NotifyType.StatusMessage);
                    }

                    // Remove all local setting values
                    ApplicationData.Current.LocalSettings.Values.Clear();

                    isUpdatingFirmware = false;

                    UpdateButtonStates();
                }));

            if (firmwareUpdateBackgroundTaskRegistration != null)
            {
                // Unregister the background task and let the remaining task finish until completion
                firmwareUpdateBackgroundTaskRegistration.Unregister(false);
            }
        }
开发者ID:oldnewthing,项目名称:old-Windows8-samples,代码行数:45,代码来源:Scenario1_FirmwareUpdate.xaml.cs

示例13: OnCompleted

 /// <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 and Unregistered";
     try
     {
         // check for the result from the background task
         args.CheckResult();
     }
     catch (Exception e)
     {
         status = e.Message;
     }
     // Pedometer background triggers are unique in a way as the background 
     // events are one-shot - Once the step-goal associated with the original 
     // task registration has been reached, that step count is a thing-of-past 
     // and shall not fire as the stepcount on that pedometer changes.
     // Unregister the background task or update the step goals here.
     task.Unregister(false);
     backgroundTaskRegistered = false;
     UpdateUIAsync(status);
 }
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:26,代码来源:Scenario4_BackgroundTask.xaml.cs

示例14: OnCompleted

 /// <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();
 }
开发者ID:GauravC12,项目名称:Windows10BackgroundBluetoothSample,代码行数:34,代码来源:MainPage.xaml.cs

示例15: OnSyncWithDeviceCompleted

        /// <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);
            }
        }
开发者ID:ChSchmidt81,项目名称:Windows-universal-samples,代码行数:62,代码来源:Scenario7_SyncDevice.xaml.cs


注:本文中的Windows.ApplicationModel.Background.BackgroundTaskCompletedEventArgs.CheckResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。