Check if TIFF file is complete
Posted
by
Davi
on Stack Overflow
See other posts from Stack Overflow
or by Davi
Published on 2011-11-16T16:20:31Z
Indexed on
2011/11/17
1:50 UTC
Read the original article
Hit count: 266
I have a FileSystemWatcher monitoring a directory that receives TIF files from a scanning device.
Its necessary to check if the scanning process is done and then read a multipage TIF file, otherwise, the FileSystemWatcher will raise the event before the file be fully scanned.
I have something like:
private void OnFileCreated(...)
{
while(IsFileLocked(path))
Thread.Sleep(time);
// OK to read
}
This is what is happening:
- Scanner creates the file
- FileSystemWatcher detects the file, but its in use
- Scanner reads the first page to the file
- Scanner releases the file
- My code leaves the while(FileInUse(path))
- My code reads the incomplete file (problem)
- Scanner adds more pages to the file
Let's say the scanner is scanning 100 pages, then, when "OK to read", the file will be incomplete (99 pages left).
So, its necessary to know if the file is complete or not. Maybe waiting some time to see if the file is modified, but this time span can be up to hours, because the scanner can get idle scanning the same TIF. Other solution would be checking some flag in the TIF file that indicates that the file is not complete(I've looked for this but don't found anything).
© Stack Overflow or respective owner