且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IOException未处理

更新时间:2023-11-22 13:03:34

    Bitmap TempImage = new Bitmap(@cwd + "\\t" + (x + 1) + ".jpg", true);  
    pictureBox.Image = (Image)TempImage.Clone();  
    TempImage.Dispose();  

Clone()方法无法实现您希望的效果.它仍然对文件保持锁定,内存映射文件对象在两个图像对象之间共享.放置第一个只是关闭对象上的一个句柄,pictureBox.Image对象仍然打开了另一个句柄.改为这样写:

The Clone() method doesn't do what you hope it does. It still keeps a lock on the file, the memory mapped file object is shared between the two image objects. Disposing the first one just closes one handle on the object, the pictureBox.Image object still has the other handle opened. Write it like this instead:

    pictureBox.Image = new Bitmap(TempImage);