none
Giving visual Feedback with async methods RRS feed

  • Question

  • Hi,

    is there a way to give the user visual feedback while calling async methods of EF in WPF ?

    the goal is to display a busyindicator while running SaveChangesAsync for example

    any hint is welcome

    Wednesday, April 1, 2015 11:36 AM

Answers

  • You just could set the Visibility property of the busy indicator (this may be an Image or any other UI element) to Visible, await your async method and then set the Visibility property back to Hidden or Collapsed:

    private async void button_Save_Click(object sender, RoutedEventArgs e)
    {
    //...
                indicator.Visibility = System.Windows.Visibility.Visible;
                await context.SaveChangesAsync ();
                indicator.Visibility = System.Windows.Visibility..Collapsed;
    }

    <!-- this (indicator) can be any UI element -->
    <TextBlock x:Name="indicator" Visibility="Collapsed">saving....</TextBlock>

    How to display a busy indicator in a UI is not related to Entity Framework in any way though. You could await any async method the same way.

    Please remember to mark helpful posts as answer to close your threads and then start a new thread in the appropriate forum if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by issam1975 Wednesday, April 1, 2015 12:54 PM
    Wednesday, April 1, 2015 12:38 PM

All replies

  • You just could set the Visibility property of the busy indicator (this may be an Image or any other UI element) to Visible, await your async method and then set the Visibility property back to Hidden or Collapsed:

    private async void button_Save_Click(object sender, RoutedEventArgs e)
    {
    //...
                indicator.Visibility = System.Windows.Visibility.Visible;
                await context.SaveChangesAsync ();
                indicator.Visibility = System.Windows.Visibility..Collapsed;
    }

    <!-- this (indicator) can be any UI element -->
    <TextBlock x:Name="indicator" Visibility="Collapsed">saving....</TextBlock>

    How to display a busy indicator in a UI is not related to Entity Framework in any way though. You could await any async method the same way.

    Please remember to mark helpful posts as answer to close your threads and then start a new thread in the appropriate forum if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by issam1975 Wednesday, April 1, 2015 12:54 PM
    Wednesday, April 1, 2015 12:38 PM
  • Perfect !
    Wednesday, April 1, 2015 12:55 PM