C#: Monitoring copied or moved files with FileSystemWatcher

后端 未结 4 1353
醉梦人生
醉梦人生 2021-02-02 03:17

I have come across several \"solutions\" here and across the web but none seem to fit the bill.

What I am looking to do is have an app monitor a folder for new files (ei

4条回答
  •  情深已故
    2021-02-02 03:35

    I have used a couple of solutions for this situation.

    1. If you can work with the creator of the file and use a renaming scheme for the file. EG. Create the File as __Name_ while being created and at the end of the process rename it to Name and the event will fire and you have a complete file.

    2. When your trigger fires check if you can get an exclusive readonly lock on the file. If you can then the write operation has been completed to the file. (I wrote something about this in another question Keep settings in sync between forms application and windows service (or any n-tier, really))

    You could possibly integrate something like #2 into your Changed Event and then you'll get the result.

提交回复
热议问题