Hey,
I have a Windows Form with a PictureBox, and I want to change the image in the PictureBox every 10 seconds, to create a slide show effect. However, I also want the form to be able to respond to user's pressing buttons on the form. But if I just use a for loop, the whole form just freezes and the PictureBox never updates its picture. Here is the code I am using:
Code:
int i = 0; //Counter to decide which image to display next
for ( ;; ) //Loop forever
{
pictureBox1.Image = nextImage(i); //Get image i from database
this.Invalidate(); //Redraw the form to update the image
Thread.Sleep(10000); //Sleep for 10000ms = 10s
i++; //Increment the counter
}
It seems that threading is needed to keep the form responsive while the loop is running, but I've given it a go and I just cannot get it working.
Any thoughts on what I need to be doing?
Thanks!