Reputation: 85
int countFiles = 0;
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(ff[countFiles]);
countFiles++;
}
ff is a List contain 40 files. The timer interval is set to 1000ms.
The exception is on the line:
pictureBox1.Image = Image.FromFile(ff[countFiles]);
System.OutOfMemoryException was unhandled
HResult=-2147024882
Message=Out of memory.
Source=System.Drawing
Upvotes: 0
Views: 88
Reputation: 12619
You need to release previous image from memory try this:
private void timer1_Tick(object sender, EventArgs e)
{
if(pictureBox1.Image != null)
pictureBox1.Image.Dispose();
pictureBox1.Image = Image.FromFile(ff[countFiles]);
countFiles++;
}
Upvotes: 3