Picture from memory

I am developing a Windows forms application. In one of my forms, I am installing a box control. It works great for a long time. But sometimes it displays a red cross, rather than displaying the actual image.

Next, I examine this and find out that this control handles exceptions internally. So I go to Debug->Exceptionsand check the corresponding fields thrown. Then I found that the red box is displayed due to the following error:

A first chance exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll

Additional information: Out of memory.

Can any body suggest me how to deal with this exception?

+5
source share
2 answers

, PictureBox, " @Jason " , :

private void ChangePictureBoxImage(Image image)
{
    pictureBox.Image.Dispose();//dispose the old image.

    pictureBox.Image = image;
}
+8

?

, . , .

0

All Articles