JElster
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.ThreadSta rt(
delegate()
{
System.Windows.Threading.D ispatcherO peration
dispatcherOp = this.spinner.Dispatcher.Be ginInvoke(
System.Windows.Threading.D ispatcherP riority.No rmal,
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.ThreadSta rt(
delegate()
{
System.Windows.Threading.D ispatcherO peration
dispatcherOp = this.spinner.Dispatcher.Be ginInvoke(
System.Windows.Threading.D ispatcherP riority.No rmal,
new Action(
delegate()
{
this.spinner.Spin = false;
this.spinner.Visibility = Visibility.Collapsed;
}
));
dispatcherOp.Completed += new EventHandler(dispatcherOp_ Completed) ;
}
));
thread2.Start();
/// DONE
}
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.ThreadSta
delegate()
{
System.Windows.Threading.D
dispatcherOp = this.spinner.Dispatcher.Be
System.Windows.Threading.D
new Action(
delegate()
{
this.spinner.Spin = true;
this.spinner.Visibility = Visibility.Visible;
}
));
dispatcherOp.Completed += new EventHandler(dispatcherOp_
}
));
thread.Start();
// DO SAVE
/// Long running save here
// HIDE Graphic
System.Threading.Thread thread2 = new System.Threading.Thread(
new System.Threading.ThreadSta
delegate()
{
System.Windows.Threading.D
dispatcherOp = this.spinner.Dispatcher.Be
System.Windows.Threading.D
new Action(
delegate()
{
this.spinner.Spin = false;
this.spinner.Visibility = Visibility.Collapsed;
}
));
dispatcherOp.Completed += new EventHandler(dispatcherOp_
}
));
thread2.Start();
/// DONE
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.