Background Task Helper

The Background Task Helper helps users interacting with background tasks in an easier manner.

Example


    // Be sure to include the using at the top of the file:
    //using Microsoft.Toolkit.Uwp;
    //using Windows.ApplicationModel.Background;

    // Register a normal, seperate process, background task
    BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("TaskName","TaskEntryPoint", new TimeTrigger(15, true));

    // This can also be written using the overload of Register with Type parameter.
    BackgroundTaskRegistration registered = BackgroundTaskHelper.Register(typeof(BackgroundTaskClass), new TimeTrigger(15, true));

    // With condition
    BackgroundTaskRegistration registered = 
        BackgroundTaskHelper.Register(typeof(BackgroundTaskClass), 
                                      new TimeTrigger(15, true), 
                                      false, true, 
                                      new SystemCondition(SystemConditionType.InternetAvailable));

    // 2 or more conditions
    BackgroundTaskRegistration registered = 
        BackgroundTaskHelper.Register(typeof(BackgroundTaskClass), 
                                      new TimeTrigger(15, true), 
                                      false, true, 
                                      new SystemCondition(SystemConditionType.InternetAvailable), 
                                      new SystemCondition(SystemConditionType.UserPresent));

    // Register a single process background task (Anniversary Update and later ONLY)
    BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("TaskName", new TimeTrigger(15, true))

You can find more examples in our unit tests

Requirements (Windows 10 Device Family)

Device family Universal, 10.0.10586.0 or higher
Namespace Microsoft.Toolkit.Uwp

API