Reputation: 3361
I have a windows forms dialog, which does something for longer time after clicking a button. Because this takes while, I want to show an animation on the dialog (an anmiated gif, avi or whatever). How can I achive this. Do i need an own thread for this (I have no experiences with threads)? Can you provide me a code snippet how to achieve this ?
Upvotes: 2
Views: 4766
Reputation: 12126
I would put the time consuming process in its own thread and display the animated gif in the UI thread. Also, it may be useful to disable the button that triggers the process so an impatient user does not click it multiple times.
Upvotes: 1
Reputation: 887451
You can show an animated GIF using a normal PictureBox control, and you can find some useful animated GIFs at Ajaxload.
However, if you're performing the operation on the UI thread, the program will freeze until it finishes.
To prevent this, use a BackgroundWorker, like this:
Add a BackgroundWorker component to your form.
Handle its DoWork
event and perform your operation there.
Handle the RunWorkerCompleted
event and hide the PictureBox.
When you want to start the operation, show the PictureBox, then call the RunWorkerAsync method.
Upvotes: 6