none
Block UI Thread RRS feed

  • Question

  • Hi,

    I want to block UI thread untill a async operation completed.

    My aim to show loader and to block the UI thread during a POST network call. It seems there is only Thread.Sleep(time) to sleep a thread, but we will not be sure about the completion time when making api calls.

    How to overcome this? 

    Thanks.


    Pradeep AJ

    Saturday, March 22, 2014 5:04 PM

Answers

  • You don't want to block the UI thread: Technical certification requirements for Windows Phone, Section 5.1.3.

    You can disable the UI using IsEnabled properties (in XAML) so that the user can't touch things while the POST is being completed.

    You can set a flag before you begin the POST, and then when the user taps buttons or menus check the flag and tell them they "can't do that right now." Until the post is done.

    You can even set items Visibility = Visibility.Collapsed to hide buttons so the user can't do things, or put a pop-up control that covers, shades or hides parts of the UI.

    If you still think you HAVE to block the UI thread and can't use any of those - then your app may need a redesign.

    What are you hoping to accomplish by blocking the UI ?


    Darin R.

    • Marked as answer by Pradeep AJ Sunday, March 23, 2014 3:22 PM
    Sunday, March 23, 2014 12:06 AM
  • You've mentioned "Loader" and "LoaderGrid" without telling us what they are, and we have no idea what you're talking about.

    To fill the screen, the Grid containing the ProgressBar should be global to the page, as the last item in LayoutRoot.

        <Grid x:Name="LayoutRoot" Background="Transparent">
            <controls:Pivot Title="MY APPLICATION">
                ...
                ...
            </controls:Pivot>
    
            <Grid x:Name="ProgressBarGrid" Background="#cc000000">
                <ProgressBar IsIndeterminate="True"/>
            </Grid>
        </Grid>

    Set ProgressBarGrid.Visibility to Visibility.Visible or Visibility.Collapsed to show or hide it.

    • Marked as answer by Pradeep AJ Monday, March 24, 2014 2:45 AM
    Sunday, March 23, 2014 8:17 PM

All replies

  • You want to block the UI thread? If you block the UI thread the loader won't work.

    http://pauliom.wordpress.com

    Saturday, March 22, 2014 7:23 PM
  • You don't want to block the UI thread: Technical certification requirements for Windows Phone, Section 5.1.3.

    You can disable the UI using IsEnabled properties (in XAML) so that the user can't touch things while the POST is being completed.

    You can set a flag before you begin the POST, and then when the user taps buttons or menus check the flag and tell them they "can't do that right now." Until the post is done.

    You can even set items Visibility = Visibility.Collapsed to hide buttons so the user can't do things, or put a pop-up control that covers, shades or hides parts of the UI.

    If you still think you HAVE to block the UI thread and can't use any of those - then your app may need a redesign.

    What are you hoping to accomplish by blocking the UI ?


    Darin R.

    • Marked as answer by Pradeep AJ Sunday, March 23, 2014 3:22 PM
    Sunday, March 23, 2014 12:06 AM
  • You should have a fullscreen overlay control over your page that says something like "Contacting Server, please wait" (preferably with a "Cancel" button). When doing the task:

    1. Set the control to Visibility.Visible

    2. Do the POST operation

    3. When the POST completes, set the control to Visibility.Collapsed

    Sunday, March 23, 2014 1:54 AM
  • You should have a fullscreen overlay control over your page that says something like "Contacting Server, please wait" (preferably with a "Cancel" button). When doing the task:

    1. Set the control to Visibility.Visible

    2. Do the POST operation

    3. When the POST completes, set the control to Visibility.Collapsed

    Hi,

    Thanks for your reply. I tried something like this by setting the height of the ProgressBar to the height of the Phone. But still it makes the background controls to be tapped. 

    Any suggestions for how to implement this?


    Pradeep AJ

    Sunday, March 23, 2014 4:34 AM
  • You don't want to block the UI thread: Technical certification requirements for Windows Phone, Section 5.1.3.

    You can disable the UI using IsEnabled properties (in XAML) so that the user can't touch things while the POST is being completed.

    You can set a flag before you begin the POST, and then when the user taps buttons or menus check the flag and tell them they "can't do that right now." Until the post is done.

    You can even set items Visibility = Visibility.Collapsed to hide buttons so the user can't do things, or put a pop-up control that covers, shades or hides parts of the UI.

    If you still think you HAVE to block the UI thread and can't use any of those - then your app may need a redesign.

    What are you hoping to accomplish by blocking the UI ?


    Darin R.

    Hi,

    Thanks for your reply. Thats really a cool idea. We can use the PhoneApplicationPage.IsEnabled to accomplish this. But, I am using Pivots with LongListSelector, when setting IsEnabled to false, it doesnt give me a disabled UI feel.

    It looks like  Normal state rather than disabled state. Am I missing something in xaml?


    Pradeep AJ


    • Edited by Pradeep AJ Sunday, March 23, 2014 4:48 AM
    Sunday, March 23, 2014 4:44 AM
  • I tried something like this by setting the height of the ProgressBar to the height of the Phone. But still it makes the background controls to be tapped.

    That doesn't quite work because of some unusual qualities of the ProgressBar control, which make it behave differently from most controls. The ProgressBar doesn't truly occupy its full Height/Width dimensions.

    You can put the ProgressBar in another container that fills the screen. For example, use a Grid. You need to give it a Background color (even Transparent works). The default background is null, which doesn't block touch events and just passes them through. Use something like this:

                <Grid Height="800" Width="480" Background="#80000000">
                    <ProgressBar IsIndeterminate="True"/>
                </Grid>

    Here I've set the Background to a semi-transparent black, which allows the controls underneath to show through but makes them appear dimmed and disabled.

    Sunday, March 23, 2014 8:47 AM
  • I tried something like this by setting the height of the ProgressBar to the height of the Phone. But still it makes the background controls to be tapped.

    That doesn't quite work because of some unusual qualities of the ProgressBar control, which make it behave differently from most controls. The ProgressBar doesn't truly occupy its full Height/Width dimensions.

    You can put the ProgressBar in another container that fills the screen. For example, use a Grid. You need to give it a Background color (even Transparent works). The default background is null, which doesn't block touch events and just passes them through. Use something like this:

                <Grid Height="800" Width="480" Background="#80000000">
                    <ProgressBar IsIndeterminate="True"/>
                </Grid>

    Here I've set the Background to a semi-transparent black, which allows the controls underneath to show through but makes them appear dimmed and disabled.

    Hi,

    Thanks for your reply. I want the LoaderGrid to occupy the entire screen. But the Pivot Item's LongListSelector hides the Grid which contains the Loader.

    Please let me know, if i have gone wrong.



    Pradeep AJ


    • Edited by Pradeep AJ Sunday, March 23, 2014 3:27 PM
    Sunday, March 23, 2014 3:22 PM
  • You've mentioned "Loader" and "LoaderGrid" without telling us what they are, and we have no idea what you're talking about.

    To fill the screen, the Grid containing the ProgressBar should be global to the page, as the last item in LayoutRoot.

        <Grid x:Name="LayoutRoot" Background="Transparent">
            <controls:Pivot Title="MY APPLICATION">
                ...
                ...
            </controls:Pivot>
    
            <Grid x:Name="ProgressBarGrid" Background="#cc000000">
                <ProgressBar IsIndeterminate="True"/>
            </Grid>
        </Grid>

    Set ProgressBarGrid.Visibility to Visibility.Visible or Visibility.Collapsed to show or hide it.

    • Marked as answer by Pradeep AJ Monday, March 24, 2014 2:45 AM
    Sunday, March 23, 2014 8:17 PM
  • You've mentioned "Loader" and "LoaderGrid" without telling us what they are, and we have no idea what you're talking about.

    To fill the screen, the Grid containing the ProgressBar should be global to the page, as the last item in LayoutRoot.

        <Grid x:Name="LayoutRoot" Background="Transparent">
            <controls:Pivot Title="MY APPLICATION">
                ...
                ...
            </controls:Pivot>
    
            <Grid x:Name="ProgressBarGrid" Background="#cc000000">
                <ProgressBar IsIndeterminate="True"/>
            </Grid>
        </Grid>

    Set ProgressBarGrid.Visibility to Visibility.Visible or Visibility.Collapsed to show or hide it.

    Thanks. I think i have misplaced the Grid containing the ProgressBar. 

    Pradeep AJ

    Monday, March 24, 2014 2:46 AM