This project has moved. For the latest updates, please go here.

WPF BusyIndicator is blocked with Main UI thread.??

Sep 25, 2011 at 8:24 AM

Hi , I am trying to use WPF Extended Toolkit like this

 

  <extToolkit:BusyIndicator x:Name="bsyind" Grid.Row="2" IsBusy="False" DisplayAfter="0">

            <ContentControl Grid.Row="2" x:Name="myUserControl" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center">

            </ContentControl>
        </extToolkit:BusyIndicator>

 


Now in code behind I 'new' my User Control and set it as content of myUserControl. Now that Usercontrol takes some time to load, as it adjust itself according to provided information , so what I want is that when user clicks a button , I show a busy indicator and when UserControl is loaded and set as contentcontrol i hide my busy indocator and I am trying to do something like this in my button click event handler

 

 Thread t = new Thread(new ThreadStart(
            delegate
            {
                Dispatcher.BeginInvoke(DispatcherPriority.DataBind, new Action<BusyIndicator>(SetValue), bsyind);
            }
            ));
            t.Start();

            MyUC suc = new MyUC();
            suc.SetConfig(listdata);
            suc.XCtrl_Clicked += new ..........
            this.myUserControl.Content = suc;

And


        private static void SetValue(BusyIndicator pbsyind)
        {
            pbsyind.IsBusy = true; ;
        }

 


But its not working , I need reference of MYUC control on my main UI thread as I need to perform other operations using this reference.

So please help me here how to show busy indicator in this scenario .

 

EDIT: Busyindicator actually shows up but when MYUC control is loaded(as main UI thread is blocked till then), whereas I want to show it when user clicks on button and hide when control is loaded.

 

Thanks,

Shah

Sep 25, 2011 at 12:29 PM

My longrunning process use lots of UI related things , so it needs to run on main UI thread.

Sep 26, 2011 at 2:19 PM

You are not using the thread properly.  Basically you have created a thread that makes a call to the UI to set the IsBusy to true which is not buying you anything.  The Dispatcher is a mechanism to route work for processing by the UI thread.  I don't know what your SetConfig method does or where listData gets populated, but this is they type of thing that needs to be performed on a background thread.  What is the long process, generating the listData or the code in SetConfig?  if it is the code in SetConfig, that is where you need to put code on a background thread.

Here is a post that talks about multi threading using the background worker:

http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/