I am writing a 3D wpf application using Viewport3D. When the user clicks the button, I have to start DoubleAnimation on AxisAngleRotation3D , but this should be done synchronously. I can't do this on animation.Completed because this animation starts the next and next recursively.
ButtonHandler should work with the user interface thread, because I hardly use Viewport3D to calculate the animation.
So, I have to start synchronous animation in the UI thread even after it has finished continuous work.
I tried this code, but it causes a dead end:
AxisAngleRotation3D axis; DoubleAnimation animation; DependencyProperty dp; var worker = new Thread(() => { Dispatcher.CurrentDispatcher.InvokeShutdown(); Dispatcher.Run(); }); worker.SetApartmentState(ApartmentState.STA); worker.Start(); AutoResetEvent animationDone = new AutoResetEvent(false); EventHandler handler = null; handler = (sender, args) => { animation.Completed -= handler; // remove self animationDone.Set(); // signal completion }; animation.Completed += handler; Dispatcher.CurrentDispatcher.Invoke(new Action(() => { axis.BeginAnimation(dp, animation); })); animationDone.WaitOne();
source share