I am creating a file using a PDFCreator
command line using Process
and start()
. I wait for a sometime using WaitForExit()
else I Kill
the process and use WaitForExit()
again.
After these steps sometimes the output file is created and sometimes not. So I check if the File.Exist()
and access the output file.
The issue I am facing is that even though the process creating the file is either killed or returned , sometimes this file is being used by another Process
(probably some other process created by PDFCreator
or a Spooler
I am not sure)
So I Wait()
for 3
seconds and poll
again for x
number of tries, then throw my exception for a failure.
I need to move the created files, and I need to check that if the file exists, then wait until the other process using it releases it or (probably find which process is using it and kill it?). If the file does not exit, I can just proceed for failure case.
How to go about it?
I can probably try to move, then if an exception for another process is using it then I can poll
and wait
.
But any clean way approach? I am not sure why the file is in use even after the Process
has been killed or returned.