none
Using a Progress Bar/Busy Indicator in WPF

    Question

  • Hi All,

    I have added a busy indicator/progress bar to my window and I would like to show it to the user when they click on a button that loads a child user control into the same window in a stack panel. I have made the busy indicator/progress bar visible at the beginning of the click event and have hidden it at the end of the event. This doesn't help me as the UI only updates after the function has been completed as I am running my long running process on the UI thread. I have searched over the internet and found that I could use dispatacher.begin invoke but that didnt help. I need help about this!!!

     

    Thanks !!

     

    Thursday, March 24, 2011 12:35 AM

Answers

All replies

  • Hi,'

           If the the long running process is not UI stuff, I would just don't use dispatcher for that. The following steps will hepl you in solving the issue

            1) Use a background thread (You can use latest Task<T>)to execute long running process
            2) Subscribe to the background thread complete event
            3) Start your progress indicator
            4)  Stop your progress indicator in the thread complete event (Step 2)
            5) If you are using Task<T>, you may use dispatcher to bring your execution back to UI thread.
     
    Do Steps 1 to 3 in the button click event.

                       

    JoseA

           


    Ajosh Jose
    Thursday, March 24, 2011 1:55 AM
  • My long running process also has UI stuff as it loads another user control into a stack panel present in the current window.
    Thursday, March 24, 2011 3:49 AM
  • The problem is that the item showing the busy indicator is on the same thread as the UI thread. This way, the UI is loaded just when you cancel or stop the busy indicator. However, it is possible to create a busy indicator on a non-UI thread:

    http://blogs.msdn.com/b/dwayneneed/archive/2007/04/26/multithreaded-ui-hostvisual.aspx

    We as developers of Catel used this technique to create the PleaseWaitWindow, which does exactly what you describe. The source code is also available.

     


    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a free open-source MVVM framework for WPF and Silverlight? Check out Catel!
    Thursday, March 24, 2011 1:57 PM
  • And I have one sample may help you: http://cid-51b2fdd068799d15.office.live.com/self.aspx/.Public/Samples%5E_2011/20110309%5E_BackgroundWorkerInLoadingForm.zip please download it from my skydrive.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 24, 2011 2:51 PM
  •  

    Hi Bob Bao and  Geert van Horrik

    My busy indicator is not a custom made one, i am using the busy indicator form the wpf extended wpf toolkit and wrapping it aroung my grid and making it true or false as I need it. In that scenario how do I change the thread that has created it. Do I have create another busy indicator of my own on a different thread?? 

    Thursday, March 24, 2011 5:05 PM
  • I am not familiar with that one, but it probably is created on the same thread. If it is not using a host visual, you cannot create it on a separate thread. Probably the busyindicator is meant for purposes where the actual work is calculated in a background thread. With the PleaseWaitWindow of Catel, you can run your work on the UI thread (thus no dispatching required), and still show an animation during that work.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a free open-source MVVM framework for WPF and Silverlight? Check out Catel!
    Friday, March 25, 2011 7:48 AM