Animations and blocking thread

132 views
Skip to first unread message

Corrado Cavalli

unread,
Dec 23, 2009, 1:17:07 AM12/23/09
to wpf-di...@googlegroups.com

Hi folks,

I have a waiting animation spinning and I need to invoke a blocking function, this causes animation to stop.

Apart  invoking function in a secondary thread is there any alternative solution/trick I’m not aware of?

 

Happy holidays!

-Corrado

 

 

Shawn Wildermuth

unread,
Dec 23, 2009, 2:27:12 AM12/23/09
to wpf-di...@googlegroups.com

Nope, you block on the UI thread, animations stop (and I think videos too). Isn't that a perfect use of the ThreadPool (or background worker if you want to be able to cancel it)?

Corrado Cavalli

unread,
Dec 23, 2009, 2:59:30 AM12/23/09
to wpf-di...@googlegroups.com

Oh yeah,

That’s probably what I’m going to do, just wanted to ask this club of gurus if i just miss something that could avoid that J

 

Thanks Shawn!

 

-Corrado

 

From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Shawn Wildermuth
Sent: mercoledì 23 dicembre 2009 08:27
To: wpf-di...@googlegroups.com
Subject: RE: [WPF Disciples] Animations and blocking thread

 

Nope, you block on the UI thread, animations stop (and I think videos too). Isn't that a perfect use of the ThreadPool (or background worker if you want to be able to cancel it)?

 

From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Corrado Cavalli
Sent: Wednesday, December 23, 2009 1:17 AM
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Animations and blocking thread

 

Hi folks,

Sacha Barber

unread,
Dec 23, 2009, 3:42:18 AM12/23/09
to wpf-di...@googlegroups.com
Nope, threading is the way.
--
Sacha Barber
sacha....@gmail.com

Laurent Bugnion, GalaSoft

unread,
Dec 23, 2009, 4:20:04 AM12/23/09
to wpf-di...@googlegroups.com

As others said, threading is the way. Note that some operations in the framework are already asynchronous (such as async web requests) so they are not blocking. Sometimes however I find that the mere operation of creating a web client causes some glitches in the animations, so I sometimes spin a new thread for that operation anyway.

 

Thankfully, with lambdas, threading is much less painful than it used to be… as long as everything works fine ;)

 

Cheers,

Laurent

Eric Burke

unread,
Dec 26, 2009, 11:39:14 AM12/26/09
to wpf-di...@googlegroups.com
Even though it's more typical to do the work in the background and dispatch to the UI thread -- there are still times where that operation causes hiccups in the animation.  If that's the case, you could create that visual on a background thread, provided the thing that's animating doesn't require user input.  See Dwayne Need's article here: http://blogs.msdn.com/dwayneneed/archive/2007/04/26/multithreaded-ui-hostvisual.aspx

I have a wrapper class for this type of visual that I've used if you are interested -- ping me off list.

Paul Stovell

unread,
Dec 31, 2009, 12:57:13 AM12/31/09
to wpf-di...@googlegroups.com
Great find Eric!

Paul
--
Paul Stovell
Reply all
Reply to author
Forward
0 new messages