Have small VB.net program (2010) that utilizes the "FileSystemWatcher" control. Control "watches" for the creation of a particular PDF file, it then moves the file to a predetermined location. PDF's are created by scanning to the "watched" file. Scans with fewer than about 30 pages are handled correctly. Larger scans are the problem.
I was getting a corrupted PDF in the move to location on larger scans because the code in the "watched" section was writing the file before the very large scans could complete. To solve that problem, I put a sleep statement to just pause the program to give the system time to fully write the PDF to file. Solved my scan problem. Put a sleep time of 60 seconds.
My solution has now created an additional problem of not allowing other processes to work during the 60 seconds. Critical programs that need to run.
Now for my question: Within the subroutine that is triggered by the creation of the file, how do I check that a file is "Completely written to disk, and there is no more activity? How to do this without using a sleep statement?
So far I've attempted to check file size, but not much luck there.
If possible, just a very short snippet of code would be very helpful, or a very detailed explanation as to how to solve my problem.
Thanks in advance!!