Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

WPF - Dispatcher.BeginInvoke - Why doesn't this work

Hi..
I have a SAVE method. I'm trying to display a graphic while saving, when the save button is clicked.
I'm trying to use the BeginInvoke before and after the save to show the graphic. But the graphic is never shown. it looks like this... What is wrong..? How do I update the UI????
thanks

void  Save()
{


// SHOW GRAPHIC


            System.Threading.Thread thread = new System.Threading.Thread(
            new System.Threading.ThreadStart(
              delegate()
              {
                  System.Windows.Threading.DispatcherOperation
                    dispatcherOp = this.spinner.Dispatcher.BeginInvoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                      delegate()
                      {
                          this.spinner.Spin = true;
                         this.spinner.Visibility = Visibility.Visible;
                      }
                  ));

                  dispatcherOp.Completed += new EventHandler(dispatcherOp_Completed);
              }
          ));

            thread.Start();



//  DO SAVE

///  Long running save here

// HIDE Graphic



            System.Threading.Thread thread2 = new System.Threading.Thread(
            new System.Threading.ThreadStart(
              delegate()
              {
                  System.Windows.Threading.DispatcherOperation
                    dispatcherOp = this.spinner.Dispatcher.BeginInvoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                      delegate()
                      {
                          this.spinner.Spin = false;
                         this.spinner.Visibility = Visibility.Collapsed;
                      }
                  ));

                  dispatcherOp.Completed += new EventHandler(dispatcherOp_Completed);
              }
          ));

            thread2.Start();






/// DONE



}
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial