|
-
Dec 5th, 2006, 12:39 PM
#1
Thread Starter
New Member
Animated (.gif) image on the form
I have a pictureBox on my windows form with the animated .GIF image. Form calls some methods that can take minute or two to run, so I thought I could change the visible property of my picture box to true and let the animation to run before method returns. The problem is that the image will remain still or will barely move. Is there any way to keep the animation going while method runs?
Thanks for your help
-
Dec 5th, 2006, 06:47 PM
#2
Re: Animated (.gif) image on the form
Your process is too busy performing the other operation to bother with updating the PictureBox. If you want two things to happen simultaneously then you need to use multiple threads. Your main thread will animate the image while a worker thread performs the long-running operation. .NET 2.0 makes this quite simple with the addition of the BackgroundWorker component. Add a BackgroundWorker to your form in the designer and add code along the following lines:
Code:
private void StartCalculation()
{
this.pictureBox1.Visible = true;
// Raise the DoWork event in a worker thread.
this.backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// Perform your long-running operation here.
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// The long-running operation has finished.
// This event is raised in the main thread.
this.pictureBox1.Visible = false;
}
Note that the DoWork event is raised in a worker thread so there may be issues with accessing controls or synchronising data, depending on exactly what you're doing. If you want to know more about multi-threading then I suggest that you follow the Articles -> Advanced .NET link in my signature and read the Managed Threading section.
-
Dec 6th, 2006, 12:37 AM
#3
Thread Starter
New Member
Re: Animated (.gif) image on the form
Thanks jmcilhinney;
I will try your solution tomorrow and will get back with the feedback. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|