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?
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.