Advertisement

05.30.2007 at 11:31PM PDT, ID: 22603877
[x]
Attachment Details

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

Asked by MSAIT in C# Programming Language

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)
        {
            try
            {
                DateTime i = DateTime.Now;
                label1.Text = "Opening Image....";
                Application.DoEvents();
                System.Drawing.Image bm = System.Drawing.Image.FromFile(SourcePath);
                label1.Text = "Converting Image....";
                Application.DoEvents();

                bm.Save(SourcePath.Replace(".", "") + "_output.Tiff", System.Drawing.Imaging.ImageFormat.Tiff);
                bm.Dispose();
                bm = null;
               
                DateTime o = DateTime.Now;
                TimeSpan u = o - i;
                label1.Text = "Conversion Complete." + u.ToString();
                Application.DoEvents();
                return true;
            }
            catch(Exception e)
                {
                    label1.Text = "Input File Not ready!" + e.Message ;
                    return false;
                }
        }Start Free Trial
[+][-]05.31.2007 at 12:09AM PDT, ID: 19186010

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Sign Up Now!
Solution Provided By: Dr-Hussain
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.02.2007 at 12:58AM PDT, ID: 19200131

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.24.2007 at 06:33PM PDT, ID: 19352884

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.03.2007 at 03:43PM PDT, ID: 19415368

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.08.2007 at 05:58PM PDT, ID: 19442190

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32