I have a list of "images" that contains about 20 photos of 1 MB each. I want to scroll through the images in the list by clicking the "Next" button. But after about 8 shots, my memory goes out.
private void button4_Click(object sender, EventArgs e)
{
index++;
if (index >= images.Count) index = 0;
CurrImage = images[index];
Bitmap b = new Bitmap((Bitmap)CurrImage.Clone());
pictureBox1.Image = b;
NewThread = new Thread(new ThreadStart(ChooseColors2));
}
The ChooseColors2 stream will use "CurrImage", so to avoid race conditions, I avoided this by creating a new bitmap as shown above.
Please note that if I use pictureBox1.Image = CurrImage; without creating a new bitmap, I do not get this error, but with the stream there will be an exception of the race condition.
source
share