title: In WinRT, how do I load an image and then wait only as long as is needed for it to load before writing to it?
body: <p>I'm using WriteableBitmapEx in a WinRT project.  I load an image into a WriteableBitmap from the users Picture library.  However, I cannot then immediately write to that image, if I do, it will be overwritten with the image itself (it seems like it's Async loading the image and then it's overwritting my drawing on top of it).  I don't know how to stop it from doing that (I tried using Await on the SetSource but that's not an Async method).  </p>
  
  <p>I've used an "Await Task.Delay(1000)" and that works, but it seems hacky because 1000ms may or may not be enough time.. I would like it to wait until the bitmap is loaded before proceeding. </p>
  
  <p>Can anyone seem off the top what I'm doing wrong or suggest how I can ensure the WriteableBitmap is loaded from the pictures library before doing any processing?  Here's the example code snippet I created:</p>
  
  <pre><code>Dim file = Await picker.PickSingleFileAsync
  
  If file Is Nothing Then
      Exit Sub
  End If
  
  Dim wbm As New WriteableBitmap(1, 1)
  wbm.SetSource(Await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
  
  ' If I don't have this, the DrawLine will not show up, if I do, it will.
  Await Task.Delay(1000)
  
  wbm.DrawLine(1, 1, 255, 255, Colors.Green)
  wbm.Invalidate()
  
  ImageMain.Source = wbm
  </code></pre>