troubleshooting Question

C# File in use problem 500 POINTS!!!!!

Avatar of MSAIT
MSAIT asked on
2 Comments2 Solutions277 ViewsLast Modified:
I have the code below which works great. However I need to loop through images in a folder to convert them. In the same process after the below routene has run I use the tiff file in some document processing. Then I need to delete the tiff file automatically. Problem is it cannot delete the last file used as it throws "File in use by another process" exeption. How can I make sure that the tiff file is no longer used in the code below after the line  bm.Save() ?
private Boolean Load_Image(string SourcePath)
                DateTime i = DateTime.Now;
                label1.Text = "Opening Image....";
                System.Drawing.Image bm = System.Drawing.Image.FromFile(SourcePath);
                label1.Text = "Converting Image....";

                bm.Save(SourcePath.Replace(".", "") + "_output.Tiff", System.Drawing.Imaging.ImageFormat.Tiff);
                bm = null;
                DateTime o = DateTime.Now;
                TimeSpan u = o - i;
                label1.Text = "Conversion Complete." + u.ToString();
                return true;
            catch(Exception e)
                    label1.Text = "Input File Not ready!" + e.Message ;
                    return false;
Sr. Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros