I have a thread that will poll the folder for new files. The problem is that he sees a new file and begins to work on it even before the file has been completely copied by another process. Because of this, the poller gets the file used by another process error.
Is there a way to check a file that you can use or receive a notification? Of course, we can use exception handling code, but is there a better way?
Technology: .NET 2.0 / C #
Update:
Learning from other answers that if we have access to the application that writes the file, then the best design is to start with some other .tmp extension, and then rename it after copying.
FileStream.Lock can be used if we do not control the source application
source
share