Part 19 - Understanding async and Awaitable Tasks

Play Part 19 - Understanding async and Awaitable Tasks

The Discussion

  • User profile image

    Being accustomed to threads these async-awaits make my head spin.

    In phone 8.0 I used to have something like:

    Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
      Dim theThread As New System.Threading.Thread(AddressOf DoSlowWork)
      theThread.IsBackground = True
      theThread.Start(New MyParametersBundledClass With {.FileToOpen = "MyDir/"})
      'Other stuff that needs to run right away before the thread above finishes!
    End Sub
    Private Sub DoSlowWork(ParameterBundle As MyParametersBundledClass)
      Dim fs As IO.FileStream = IO.File.OpenRead(ParameterBundle.FileToOpen)
      'Some processing here to populate MyParameters As MyParametersClass...
      Deployment.Current.Dispatcher.BeginInvoke(New Action(Of MyParametersClass)(AddressOf UpdateViewModel), MyParameters)
    End Sub
    Private Sub UpdateViewModel(NewStuff As MyParametersClass))
    End Sub

    Now that in phone 8.1 the OpenRead is awaitable I have a feeling I should be doing more changes than just adding Async to all the Subs all the way till MainPage_Loaded; But I have no idea what?

    Dim fs As System.IO.Stream = Await Windows.Storage.ApplicationData.Current.LocalFolder.OpenStreamForRead(ZipPath)


  • User profile image

    Thanks Bob, you made it really easy for me to understand this concept. I learnt a lot from you on channel9 and you're doing great.

Add Your 2 Cents