本文整理汇总了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);
}
示例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);
}
});
}
示例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);
}
});
}
}
示例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);
}
}));
}
示例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);
}
});
}
}
示例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 )
}
}
示例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);
}
示例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;
}
}
示例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);
}
});
}
示例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);
}
});
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
}