Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I've got the following code that attaches a thumbnail image coming from an ImageList to a PictureBox. However, it is causing my application to not close once the code block gets executed. I suspect this has got to do with the resource(the photo file) not being released properly, I may be wrong though. Any experts advice would be greatly appreciated. All the best!

<br /> Image.GetThumbnailImageAbort myCallback =<br /> new Image.GetThumbnailImageAbort(ThumbnailCallback);<br /> Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width-5, this.pictureBox1.Size.Height-5, myCallback, IntPtr.Zero);<br />// e.Graphics.DrawImage(myThumbnail, 150, 75);<br /> <br /> this.pictureBox1.Image = myThumbnail;<br /> this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

Posted

The code works fine for me.
public partial class Form1 : Form<br />    {<br />        public Form1()<br />        {<br />            InitializeComponent();<br /><br />            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);<br />            Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width - 5, this.pictureBox1.Size.Height - 5, myCallback, IntPtr.Zero);<br />            this.pictureBox1.Image = myThumbnail;<br />            this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;<br />        }<br /><br />        private bool ThumbnailCallback()<br />        {<br />            return true;<br />        }<br />    }

And the app exits fine.

Failure to exit is usually caused by a thread not terminating correctly. Does your abort callback get triggered? Does it correctly return?

You don't need to release the Image. This is handled by the Imagelist for you provided that you have added your image list via the designer or correctly disposed of it manually, either way though, this wouldn't prevent your app from closing.

After you have closed your app, and it's stuck without terminating, try hitting the pause button and looking at the call stack to see where it is stuck.

 
Share this answer
 
<>
 
Share this answer
 
Comments
CHill60 25-Feb-15 10:41am    
What was the point of this???


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900