c# - How to wait for a file to be released by another external process? -
i creating file using pdfcreator
command line using process
and start()
. wait sometime using waitforexit()
else kill
process , use waitforexit()
again.
after these steps output file created , not. check if file.exist()
, access output file.
the issue facing though process creating file either killed or returned , file being used process
(probably other process created pdfcreator
or spooler
not sure)
so wait()
3
seconds , poll
again x
number of tries, throw exception failure.
i need move created files, , need check if file exists, wait until other process using releases or (probably find process using , kill it?). if file not exit, can proceed failure case.
how go it?
i can try move, if exception process using can poll
, wait
.
but clean way approach? not sure why file in use after process
has been killed or returned.
your root issues fact using "kill" on creation process before has completed task. ideally should wait completion before proceeding or experience lockouts getting now.
that said in order check if file in use , available moved can try using code taken here:
protected virtual bool isfilelocked(fileinfo file) { filestream stream = null; try { stream = file.open(filemode.open, fileaccess.readwrite, fileshare.none); } catch (ioexception) { //the file unavailable because is: //still being written //or being processed thread //or not exist (has been processed) return true; } { if (stream != null) stream.close(); } //file not locked return false; }
Comments
Post a Comment