Sharing Violation when deleting pdf file after cancelling

If you are a C/C++/C# developer and have any questions about using our products from your application here is the place to post them.
Post Reply
Jonners
Posts: 6
Joined: Wed Apr 07 2004
Location: UK

Sharing Violation when deleting pdf file after cancelling

Post by Jonners »

Hello, I am using the evaluation version of the pdf converter v2.5 (Developer). My program allows the user to cancel a print job before the pdf file is fully created. I must delete the half-created pdf file, so in my abort procedure I use the following code:

m_pDC->AbortDoc();
pApp->DisablePDFPrinter();

if (! DeleteFile(pApp->m_strPDFFileName))
AfxMessageBox("Clean up failed");

(m_pDC and pApp are simply pointers to the Device Context and the App respectively)

I consistently get an error (code = 32 - Sharing Violation - "The process cannot access the file because it is being used by another process") when trying to delete the file.

However, stepping through the code in debug successfully deletes the file without error! Does the Amyuni printer hold on to the last file for a short period of time even after calling DisablePDFPrinter(); ? This would explain the fact that it works in a very slow environment (debug) but not in normal running mode.

Any thoughts or advice will be much appreciated.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Yes, it is the spooler that has the file open, you need to wait for the spooler to closer it by monitoring the directory by example.
Jonners
Posts: 6
Joined: Wed Apr 07 2004
Location: UK

Post by Jonners »

Thanks Joan.

I have used an AfxMessageBox between the call to AbortDoc() and the call to DeleteFile() to tell the user that their file will be deleted. The user's delay in pressing 'OK' gives the spooler enough time to release the file before I come to deleting it.

Not an ideal solution, and it might not work on all systems, but it is extremely rare for our users to cancel a job anyway.

Regards,

John
Post Reply