gpt4 book ai didi

c# - 配置 filesystemwatcher 使其仅在文件被完全复制时引发创建的事件

转载 作者:行者123 更新时间:2023-12-03 21:36:19 25 4
gpt4 key购买 nike

当有一个大文件移动到监视文件夹中时,即使在文件被完全复制之前它也会引发 created 事件。

在创建的事件中复制此类文件会导致“文件正在被另一个进程使用”错误。

我使用了一个尝试复制文件的线程,直到它被允许这样做。但我仍然不满意。

我们能否配置 FileSystemWatcher,以便仅在文件完全复制后才引发 created 事件?谢谢。

最佳答案

documentation for the FileSystemWatcher class具体说明您观察到的行为

Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.

您可以检查文件的锁是否已释放,然后知道复制已完成?

关于c# - 配置 filesystemwatcher 使其仅在文件被完全复制时引发创建的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8733816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com