The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
UI Thread block on Async web service call RRS feed

  • Question

  • I have a strange situation.  When a user clicks a LOGIN button, I fire off a 

    VisualStateManager.GoToState(this"Busy"false);

    To indicate a “busy” state.  The problem is, this visual state shows up after a long wait on the UI.  So picture this…  In the following case, the VisualState takes a long time after the DoLogin is finished with the call.

            private void btnLogin_Click(object sender, RoutedEventArgs e)

            {

                VisualStateManager.GoToState(this"Busy"false);

                DoLogin();

            }

    However if I do this, it works fine:

            private void btnLogin_Click(object sender, RoutedEventArgs e)
            {
                VisualStateManager.GoToState(this"Busy"false);
                return;
            }

    I know there’s something blocking here, but the DoLogin() method is merely calling an asynchronous web service call, so in theory it shouldn’t be blocking the UI thread?

    Friday, September 20, 2013 11:18 PM

Answers

  • Hi chrisdudes,

    In your Login Button Click use code like :

    private void btnLogin_Click(object sender, RoutedEventArgs e)
            {
                Dispatcher.BeginInvoke(()=> {
                VisualStateManager.GoToState(this, "Busy",    false);
                DoLogin();
    });
            }

    May It solves the problem.

    Regards,


    Pardeep

    • Marked as answer by chrisdudes Saturday, September 21, 2013 7:48 PM
    Saturday, September 21, 2013 11:04 AM

All replies

  • Right, when it's really async it should not block the ui.
    Are you sure there is no sync code in your login function ?

    Saturday, September 21, 2013 12:35 AM
  • 100% positive.  I've been doing this for a lonnnnnnnnnnng time.  I just thought perhaps there was some unknown incident that someone may have seen before.  Doesn't sound familiar?
    Saturday, September 21, 2013 7:39 AM
  • Sorry, i never run into this problem with the visualstatemanager :/

    Saturday, September 21, 2013 9:42 AM
  • Hi chrisdudes,

    In your Login Button Click use code like :

    private void btnLogin_Click(object sender, RoutedEventArgs e)
            {
                Dispatcher.BeginInvoke(()=> {
                VisualStateManager.GoToState(this, "Busy",    false);
                DoLogin();
    });
            }

    May It solves the problem.

    Regards,


    Pardeep

    • Marked as answer by chrisdudes Saturday, September 21, 2013 7:48 PM
    Saturday, September 21, 2013 11:04 AM
  • THANK YOU PARDEEP.  I should have thought of this.  Now I need to manage the threads... but the UI works.
    Saturday, September 21, 2013 7:48 PM