Background​Task​Completed​Event​Args Background​Task​Completed​Event​Args Background​Task​Completed​Event​Args Background​Task​Completed​Event​Args Class

Definition

Represents completion information for a task at the time a completion notification is sent.

public : sealed class BackgroundTaskCompletedEventArgs : IBackgroundTaskCompletedEventArgspublic sealed class BackgroundTaskCompletedEventArgs : IBackgroundTaskCompletedEventArgsPublic NotInheritable Class BackgroundTaskCompletedEventArgs Implements IBackgroundTaskCompletedEventArgs// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following example shows how to use the BackgroundTaskCompletedEventArgs class with a BackgroundTaskCompletedEventHandler delegate to monitor background task completion while the app is in the foreground. Note that this depends on the background task to report status via LocalSettings.

private async void OnCompleted(IBackgroundTaskRegistration task,
                               BackgroundTaskCompletedEventArgs args)
{
    var settings = ApplicationData.Current.LocalSettings;
    var key = task.TaskId.ToString();
    string status = settings.Values[key].ToString();

    //
    // UI element updates should be done asynchronously.
    //
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
    () =>
    {
        ExampleProgressElement.Text = "Task completed with status: " + status;
    });
}

Remarks

The system generates this class and passes it as an argument to the application's BackgroundTaskCompletedEventHandler handler.

Properties

InstanceId InstanceId InstanceId InstanceId

Gets the identifier of the background task instance for this completion status notification.

public : PlatForm::Guid InstanceId { get; }public Guid InstanceId { get; }Public ReadOnly Property InstanceId As Guid// You can use this property in JavaScript.
Value
PlatForm::Guid Guid Guid Guid

A unique identifier generated by the system when it creates the background task instance.

Methods

CheckResult() CheckResult() CheckResult() CheckResult()

Throws an exception if the background task completed event has reported an error.

public : void CheckResult()public void CheckResult()Public Function CheckResult() As void// You can use this method in JavaScript.

Remarks

This method should be called from within a try block. If the background task completed event reported an error, it will be caught as an exception in the subsequent catch clause.