How to force FileSystemWatcher to wait till the file downloaded?

前端 未结 4 967
面向向阳花
面向向阳花 2021-02-08 20:11

I am downloading a file and want to execute the install only after the download is complete. How do I accomplish this? Seems like FileSystemWatcher onCreate event would do this

4条回答
  •  甜味超标
    2021-02-08 20:45

    If you insist on using FileSystemWatcher you would probably have to account for the fact that a file of some size isn't created (uploaded) in one single operation. The filesystem is likely to produce 1 created and x changed events before the file is ready for use.

    You could catch the created events and create new (dedicated) threads (unless you already have an ongoing thread for that file) in which you loop and periodically try to open the file exclusively. If you succeed, the file is ready.

提交回复
热议问题