locked
await Task from Dispatcher.RunAsync(..)

    Question

  • I'm trying to call an awaitable Task I wrote from within an event handler.

    Specifically,  when I receive a MobileBroadbandAccountWatcher.AccountAdded event I'm trying to update a few UI elements, and call a method I created that connects the devices and accounts.

    My code currently looks like this.  I'm just trying to create and connect these MobileBroadbandAccount objects back on the UI thread.

    async void _accountWatcher_AccountAdded(MobileBroadbandAccountWatcher sender, MobileBroadbandAccountEventArgs args){ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatchPriority.Normal, ()=> { NotifyUser("AccountAdded"); NotifyUser("Account Id " + args.NetworkAccountId); await ConnectAccountsAsync(); // This line here is what I can't figure out }


    Monday, September 17, 2012 11:31 PM

Answers

  • I think I may have figured this out, guess I should have waited a little longer to post.

    wait Dispatcher.RunAsync(Windows.UI.Core.CoreDispatchPriority.Normal, ()=>
    {
    
    NotifyUser("AccountAdded");
    NotifyUser("Account Id " + args.NetworkAccountId);
    
    await ConnectAccountsAsync(); // This line here is what I can't figure out
    }
    

    I included 'async' in front of my Lamda expression to make it look like this and so far it seems to do what I want .

    wait Dispatcher.RunAsync(Windows.UI.Core.CoreDispatchPriority.Normal, async ()=>
    {
    
    NotifyUser("AccountAdded");
    NotifyUser("Account Id " + args.NetworkAccountId);
    
    await ConnectAccountsAsync(); // This line here is what I can't figure out
    
    

    Monday, September 17, 2012 11:42 PM