locked
Adding await to this Dispatcher.RunAsync cause error RRS feed

  • Question

  • Below message is showed even I have added the below namespaces if i hover the mouse over the Dispatcher

    "This call is not awaited, execution of the current method continues before the call is completed. Consider applying the await operator to the result of the call."


    using Windows.System.Threading;
    using System.Threading;

    Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    {   

    PanelNoInternet.Visibility =   Visibility.Visible;                                                        

    PanelUnknownInternet.Visibility = Visibility.Collapsed;                                                    

    PanelCableInternet.Visibility =   Visibility.Collapsed;                                                    

    PanelMobileInternet.Visibility =  Visibility.Collapsed;                                                    

    PanelWifiInternet.Visibility = Visibility.Collapsed;
                                                                                  
    });

    How to solve this issue.

    Thanks

    Wednesday, December 11, 2013 5:27 AM

Answers

  • Do you have a using directive for 'System'?
    • Marked as answer by FireDance Thursday, December 12, 2013 1:43 AM
    Wednesday, December 11, 2013 10:02 PM
    Moderator

All replies

  • The namespace usings aren't relevant to this.

    As the warning suggests, you can apply the await operator to the RunAsync call to wait for it to finish:

    await Dispatcher.RunAsync(...)

    --Rob

    Wednesday, December 11, 2013 7:12 AM
    Moderator
  • When try to run this code with this syntax:

    private async void ShowConnectionStatus(InternetConnectionType connectiontype)
    {

             await Dispatcher.RunAsync(...)

       ....

    }

    The error message:

    'await' requires that the type 'Windows.Foundation.IAsyncAction' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?


    • Edited by FireDance Wednesday, December 11, 2013 10:39 AM typo
    Wednesday, December 11, 2013 10:39 AM
  • Do you have a using directive for 'System'?
    • Marked as answer by FireDance Thursday, December 12, 2013 1:43 AM
    Wednesday, December 11, 2013 10:02 PM
    Moderator