?
Solved

Process Not Releasing

Posted on 2004-08-27
6
Medium Priority
?
310 Views
Last Modified: 2012-08-13
My coworker has an application that he is working on that views dicom images using the ezdicom activex tool.  He added functionality to print the images into the application.  The only way he could figure to go about it was to use a function in the activex tool that writes the image to a file and then say graphics.drawimage from that file.  It works fine and prints, but the problem is that in order to become efficient, after printing the image he tries to delete the file that was generated from the image and gets an error saying that the file could not be accessed because it was in use by another process.  For the life of us, we cannot figure out what is causing this error, because if we change the image and click print again, causing it to write a new image to the same file, it works with not problem.  It is just when it tries to delete the file.  Any ideas what could be causing this????????????

Thanks,
Kendal
0
Comment
Question by:gvector1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:sonicblis
ID: 11914035
Can you post the code you are using to write the image to the directory?  It is likely that there is a lock placed by the object opening the file for writing that you are not explicitly releasing, similar to when you create a text file for writing with a TextWriter and don't call the .Close() method.
0
 

Author Comment

by:gvector1
ID: 11914889
It is an activex control that writes the file.  There is no explicit close methods within the control to release the file.  Here is all of the printing code that we are using.

            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                  double factor=0;
//                  get_the_imagesize(width, height);
                  the_ezdicom.DCMsaveToFile = @"c:\emr\tempdcm.jpg";
//                  // Draw a picture.
                  if (Convert.ToInt32(width)>1000)
                  {
//                        if (Convert.ToInt32(width) == 2048)
//                              factor = .415;
//                        else if (Convert.ToInt32(width) == 2500)
//                              factor = .34;
                        factor = .34;
                        double pwidth = (factor * Convert.ToInt32(width));
                        double pheight = (factor * Convert.ToInt32(height));
                        e.Graphics.DrawImage(Image.FromFile(@"c:\emr\tempdcm.jpg"),0,0,Convert.ToInt32(pwidth), Convert.ToInt32(pheight));
                  }
                  else
                  {
                        e.Graphics.DrawImage(Image.FromFile(@"c:\emr\tempdcm.jpg"),75,75,Convert.ToInt32(width.Trim()),Convert.ToInt32(height.Trim()));
                  }
//                  Indicate that this is the last page to print.
                  e.HasMorePages = false;

            }

            private void menuItem2_Click(object sender, System.EventArgs e)
            {
                  PrintDialog printDialog1 = new PrintDialog();
                  printDialog1.Document = printDocument1;
                  DialogResult result = printDialog1.ShowDialog();
                  
                  if (result == DialogResult.OK)
                  {
                        printDocument1.Print();
                  }

            }

All of this code currently works, but if I add a line (File.Delete("C:\emr\tempecm.jpg")) at the end of menuItem2_click() event, I get the in use by other process error.  Again, the control is an EZDicom Control.  What do you think?

Thanks,
Kendal
0
 
LVL 3

Expert Comment

by:gillgates
ID: 11933171
You could try setting the variable to null...

private void menuItem2_Click(object sender, System.EventArgs e)
{
       PrintDialog printDialog1 = new PrintDialog();
       printDialog1.Document = printDocument1;
       DialogResult result = printDialog1.ShowDialog();
               
       if (result == DialogResult.OK)
       {
             printDocument1.Print();
       }
       the_ezdicom = null;
       File.Delete("C:\emr\tempecm.jpg");
}

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:gvector1
ID: 11942738
I don't believe we will be able to do that as it is an activex control that is also displaying the image and accepting user interaction.  Any other suggestions????

Thanks,
Kendal
0
 
LVL 5

Accepted Solution

by:
Kelmen earned 2000 total points
ID: 12004970
We faced similar problem with COM object.

Maybe you should try the GC.Collect(), to force a resourses release after you done with your printing.

Our experience is with CDONTS stuff, have to use the GC.Collect() twice! And even sometime it also doesn't work (on rare occasion). The requirement changed at later so we abandon it.
0
 

Author Comment

by:gvector1
ID: 12006872
I cannot believe it.  It WORKED!!!!!  Thanks a million.  So do you think it was just the dicom control not releasing the file after using it????  The points are yours.

Thanks again,
Kendal
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question