Share via


BackgroundTaskCompletedEventArgs Class

Definition

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

public ref class BackgroundTaskCompletedEventArgs sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class BackgroundTaskCompletedEventArgs final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class BackgroundTaskCompletedEventArgs
Public NotInheritable Class BackgroundTaskCompletedEventArgs
Inheritance
Object Platform::Object IInspectable BackgroundTaskCompletedEventArgs
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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

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

Methods

CheckResult()

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

Applies to