共用方式為


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 引進)

範例

下列範例示範如何在應用程式位於前景時,搭配 BackgroundTaskCompletedEventHandler 委派使用 BackgroundTaskCompletedEventArgs 類別來監視背景工作完成。 請注意,這取決於透過 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()

如果背景工作完成事件回報錯誤,則會擲回例外狀況。

適用於