title: Windows8 backgroundtask with async tasks (deferral)
body: <p>I want to update live tiles on Background Task winmd.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Async Sub Run(taskInstance As IBackgroundTaskInstance) Implements IBackgroundTask.Run
          Dim deferral As BackgroundTaskDeferral = taskInstance.GetDeferral()
          UpdateLiveTile()
          deferral.Complete()
  End Sub
  
  'and
  
  Public Shared Async Sub UpdateLiveTile()
  ....
   await UpdateTileImage...something
  End Sub
  </code></pre>
  
  <p>If I make the code like that, the Background task exits the process before <code>UpdateTileImage</code>.
  It means that the <code>deferral.Complete()</code> is reached before doing the whole procedure.</p>
  
  <p>Therefore, I tried to change UpdateLiveTile as a Async Task like:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Async Sub Run(taskInstance As IBackgroundTaskInstance) Implements IBackgroundTask.Run
          Dim deferral As BackgroundTaskDeferral = taskInstance.GetDeferral()
          Await UpdateLiveTile()
          deferral.Complete()
  End Sub
  
  ' and
  
  Public Shared Async Function UpdateLiveTile() as Task
  ....
  End Function
  </code></pre>
  
  <p>But the compiler throws an error something like "changing method signature to use one of....." which probably tells that I cannot fire the function as a Task in Windows Runtime, not in a normal .Net framework.</p>
  
  <blockquote>
    <p>Actual error message : Method 'BackgroundTasks.NS.UpdateLiveTile()'
    has a parameter of type 'System.Threading.Tasks.Task' in its
    signature.  Although this type is not a valid Windows Runtime type, it
    implements interfaces that are valid Windows Runtime types.  Consider
    changing the method signature to use one of the following types
    instead: ''.  BackgroundTasks</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/raw0I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/raw0I.png" alt="error position"></a>
  (it should be both Public and Shared function)</p>
  
  <p>In summary, I just want to make sure the whole procedure can be done before calling deferral.Complete(). Thanks!</p>