BackgroundTaskCompletedEventArgs 类

定义

表示发送完成通知时任务的完成信息。

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
继承
Object Platform::Object IInspectable BackgroundTaskCompletedEventArgs
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

以下示例演示如何将 BackgroundTaskCompletedEventArgs 类与 BackgroundTaskCompletedEventHandler 委托一起使用,以便在应用位于前台时监视后台任务完成情况。 请注意,这取决于通过 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;
    });
}

注解

系统生成此类,并将其作为参数传递给应用程序的 BackgroundTaskCompletedEventHandler 处理程序。

属性

InstanceId

获取此完成状态通知的后台任务实例的标识符。

方法

CheckResult()

如果后台任务已完成事件报告了错误,则引发异常。

适用于