监测文件 - 如何知道一个文件是完整的 [英] Monitoring files - how to know when a file is complete
问题描述
我们有监控的新文件,使用FileSystemWatcher的一个目录中的几个.NET应用程序。该文件是从另一个位置,通过FTP等上传复制当他们进来,文件以这种或那种方式处理。但是,我从来没有见过一个满意的答案的一个问题是:对于大文件,一个人如何知道什么时候被监视的文件仍然被写入?显然,我们需要等到文件是完整的,封闭之前,我们开始处理它们。在FileSystemWatcher的事件,事件的args似乎并没有解决这个问题。
We have several .NET applications that monitor a directory for new files, using FileSystemWatcher. The files are copied from another location, uploaded via FTP, etc. When they come in, the files are processed in one way or another. However, one problem that I have never seen a satisfactory answer for is: for large files, how does one know when the files being monitored are still being written to? Obviously, we need to wait until the files are complete and closed before we begin processing them. The event args in the FileSystemWatcher events do not seem to address this.
推荐答案
你有没有尝试过的文件中获取一个写锁?如果它被写入,这应该会失败,你知道息事宁人了一下......
Have you tried getting a write lock on the file? If it's being written to, that should fail, and you know to leave it alone for a bit...
这篇关于监测文件 - 如何知道一个文件是完整的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!