I am monitoring a folder for new files and need to process them. The problem is that occasionally file opening fails, because system has not finished copying it.
Wha
Not sure about "the correct way", but you could use the monitoring tool (FileSystemWatcher
I guess) to fill an internal queue that you use for delayed processing. Or better yet: just use a queue to place files in that had the open fail, so you can retry them later.
It depends, a retry loop is probably the best you can do, if you have no control over the copy process.
If you do have control:
one approach that i take always is to create a file in the end of my copy/transfer named "token.txt" without content. The idea is that this file will be created just in the end of the transfer operation, so you can monitor this file creation and when this file is created, you start to work with your files. Don't forget to erase this token file always when you start to process your files.