if (Image.FromFile(imageFile) != null)
{
Image.FromFile(imageFile).Dispose();
}
Bad You load the image from the file, checking if the result is zero ... then load it again into the new result so that you can destroy it. Although the last part is stupid, it is not harmful. The first part, however, since the resulting one is Imagenever deleted properly (if / when the GC collects it, the type finalizer Imageshould manage unmanaged resources, but this is not wise to rely on).
, Image.FromFile null. , OutOfMemoryException.
, if else .
, OutOfMemoryException , , .
foreach :
try
{
Image image = Image.FromFile(imageFile);
PictureBox eachPictureBox = new PictureBox();
eachPictureBox.Size = new Size(100,100);
eachPictureBox.Location = new Point(iCtr * 100 + 1, 1);
eachPictureBox.Image = Image.FromFile(imageFile);
iCtr++;
panel1.Controls.Add(eachPictureBox);
}
catch(OutOfMemoryException) { }