title: Background Task in UWP - TimeTrigger and SystemTrigger registering null value in builder.SetTrigger
body: <p>I'm attempting to set up a Background task to run every 15 minutes from my UWP app, but despite the app registering successfully it isn't being triggered. There's tonnes of material on this around so to quickly sum up what I've done so far:</p>
  
  <ol>
  <li>Created Windows Runtime Component project.</li>
  <li>Added BackgroundSync.cs implementing <code>IBackgroundTask</code>.</li>
  <li>Referenced WinRT project from my UI project.</li>
  <li>Registered background task in package.appmanifest, including Timer and System event trigger boxes checked.</li>
  <li>Registered BackgroundSync in App.xaml.cs, code below.</li>
  <li>Verified that BackgroundSync is a registered background task in Powershell.</li>
  <li>I manually triggered my BackgroundSync task successfully in debug > Lifecycle Events.</li>
  </ol>
  
  <p>Here is my code to register the task:</p>
  
  <pre><code>    private static async Task&lt;BackgroundTaskRegistration&gt; SetupBackgroundSync()
      {
          await BackgroundExecutionManager.RequestAccessAsync();
  
          var builder = new BackgroundTaskBuilder();
  
          var TaskName = "BackgroundSync";
  
          foreach (var t in BackgroundTaskRegistration.AllTasks)
          {
              if (t.Value.Name == TaskName)
              {
                  t.Value.Unregister(true);
              }
          }
  
          builder.Name = TaskName;
          builder.TaskEntryPoint = typeof(Background.BackgroundSync).FullName;
          builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
  
          builder.SetTrigger(new TimeTrigger(15, false));
  
          BackgroundTaskRegistration task = builder.Register();
  
          return task;
      }
  </code></pre>
  
  <p>The only issue I can identify is that on creation of the <code>BackgroundTaskRegistration</code> object I can see that the Trigger is null. This shows null for and trigger type other than <code>ApplicationTrigger</code>.</p>
  
  <p>I have seen a post <a href="https://stackoverflow.com/questions/38526948/timetrigger-not-firing-backgroundtask-uwp">here</a> in which the poster who's answer is accepted states that this null showing in the task object is to be expected, however the solution offered has not helped.</p>
  
  <p>It's worth also stating that when I run <code>RequestAccessAsync()</code> the value I get back is actually <code>BackgroundAccessStatus.AllowedSubjectToSystemPolicy</code> which I feel must have implications. I've seen in some places that <code>RequestAccessAsync()</code> should be called from the UI thread and I'm calling this from App.xaml.cs before registering my tasks.</p>
  
  <p>Does anyone have any other ideas of potential reasons for this?</p>
  
  <p><strong>Update 07-10</strong></p>
  
  <p>Code in my test project for this background task issue:</p>
  
  <p>RegistrationHelper.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Windows.ApplicationModel.Background;
  
  namespace Tasks
  {
      public sealed class RegistrationHelper
      {
  
          public async Task&lt;BackgroundTaskRegistration&gt; RegisterTasks()
          {
              //Returns AllowedSubjectToSystemPolicy
              await BackgroundExecutionManager.RequestAccessAsync();
  
              var builder = new BackgroundTaskBuilder();
  
              var TaskName = "BackgroundTask1";
  
              foreach (var t in BackgroundTaskRegistration.AllTasks)
              {
                  if (t.Value.Name == TaskName)
                  {
                      t.Value.Unregister(true);
                  }
              }
  
              builder.Name = TaskName;
              builder.TaskEntryPoint = typeof(BackgroundTask1).FullName;
              builder.AddCondition(new     SystemCondition(SystemConditionType.InternetAvailable));
  
              builder.SetTrigger(new TimeTrigger(15, false));
  
              BackgroundTaskRegistration task = builder.Register();
  
              return task;
  
          }
  
      }
  }
  </code></pre>
  
  <p>Called in my App.xaml.cs here.</p>
  
  <pre><code>    public App()
      {
          this.InitializeComponent();
          this.Suspending += OnSuspending;
  
          Tasks.RegistrationHelper registrationhelper = new Tasks.RegistrationHelper();
  
          var task = registrationhelper.RegisterTasks();
      }
  </code></pre>
  
  <p>My background task is:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Windows.ApplicationModel.Background;
  
  namespace Tasks
  {
      public sealed class BackgroundTask1 : IBackgroundTask
      {
  
          public void Run(IBackgroundTaskInstance taskInstance)
          {
  
              while (true) { }
  
          }
  
      }
  }
  </code></pre>
  
  <p>Solution structure. BackgroundTaskTest is UWP Blank app. Tasks is a UWP Windows Runtime Component:</p>
  
  <p><a href="https://i.stack.imgur.com/ksKw7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ksKw7.png" alt="Solution structure. BackgroundTaskTest is UWP Blank app. Tasks is a UWP Windows Runtime Component."></a></p>
  
  <p>And lastly, my PackageManifest:</p>
  
  <pre><code>&lt;Extensions&gt;
      &lt;Extension Category="windows.backgroundTasks" EntryPoint="Tasks.BackgroundTask1"&gt;
        &lt;BackgroundTasks&gt;
          &lt;Task Type="systemEvent" /&gt;
          &lt;Task Type="timer" /&gt;
        &lt;/BackgroundTasks&gt;
      &lt;/Extension&gt;
    &lt;/Extensions&gt;
  </code></pre>