views:

164

answers:

2

I have a .NET WinForms application with an animated GIF in a PictureBox. It's a loading animation, shown while a BackgroundWorker does some processing in another thread. I load the image by setting the Image property and it animates on its own.

All is fine until I minimize and restore the application. At which point, the image stops animating and just displays whatever frame it was last on.

Note that:

  • The background thread still runs fine and none of the "business" of the application is affected.
  • Subsequently-displayed animated GIFs do work fine (unless the application is minimized again).

Does anyone know what causes this problem? Any workarounds?

A: 

I don't know what causes it but what if you detect when it's minimized and every time it's restored redisplay it?

RCIX
+1  A: 

Apparently the PictureBox explicitly stops animation whenever the window is obscured. The PictureBox should be invalidated and repainted when the window is no longer obscured, but the invalidation event doesn't happen automatically on Vista.

One workaround is to add a timer to your form that invokes PictureBox.Invalidate() every 500ms. This will ensure that the animation never stops.

See this MSDN thread for more information.

Ashley Tate
Interesting and thanks for the link. Glad to know someone else has the issue too. The workaround is quite annoying but the best we have I think.
lc