gvector1
asked on
Process Not Releasing
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
Thanks,
Kendal
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.
ASKER
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(o bject sender, System.Drawing.Printing.Pr intPageEve ntArgs e)
{
double factor=0;
// get_the_imagesize(width, height);
the_ezdicom.DCMsaveToFile = @"c:\emr\tempdcm.jpg";
// // Draw a picture.
if (Convert.ToInt32(width)>10 00)
{
// 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\t empdcm.jpg "),0,0,Con vert.ToInt 32(pwidth) , Convert.ToInt32(pheight));
}
else
{
e.Graphics.DrawImage(Image .FromFile( @"c:\emr\t empdcm.jpg "),75,75,C onvert.ToI nt32(width .Trim()),C onvert.ToI nt32(heigh t.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\tempe cm.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
private void printDocument1_PrintPage(o
{
double factor=0;
// get_the_imagesize(width, height);
the_ezdicom.DCMsaveToFile = @"c:\emr\tempdcm.jpg";
// // Draw a picture.
if (Convert.ToInt32(width)>10
{
// 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
}
else
{
e.Graphics.DrawImage(Image
}
// 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\tempe
Thanks,
Kendal
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\tempec m.jpg");
}
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\tempec
}
ASKER
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
Thanks,
Kendal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Thanks again,
Kendal