配置FileSystemWatcher的,这样它提出只有当文件被完全复制创建活动 [英] configuring filesystemwatcher such that it raises created event only when the file is fully copied

查看:100
本文介绍了配置FileSystemWatcher的,这样它提出只有当文件被完全复制创建活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有一个大的文件移动到监视文件夹,它提出了创建甚至在文件被完全复制的事件。

When there is a big file moved into the watched folder,it raises created event even before the file is copied fully.

复制这样的文件,文件正在被另一个进程的错误。

Copying such files within the created event causes 'file being used by another process' error.

我使用一个线程,试图复制该文件,直到它被允许做so.but我仍然不满意。

I used a thread that tries to copy the file until it is allowed to do so.but i am still not satisfied.

我们能配置 FileSystemWatcher的使得创建事件引发后,方可文件完全复制?谢谢。

Can we configure FileSystemWatcher such that the created event is raised only after the file is fully copied?thanks.

推荐答案

的的为FileSystemWatcher类文档明确规定你观察到的行为

The documentation for the FileSystemWatcher class specifically states your observed behaviour

常见文件系统的操作可能会引发多个事件。例如,当一个文件被从一个目录移动到另一个,几个调用onChanged和一些OnCreated和OnDeleted事件可能提出。移动一个文件是一个复杂的操作,由多个简单的操作,因此提高多个事件。同样地,某些应用(例如,防病毒软件)可能会导致了由FileSystemWatcher的检测到的附加文件系统事件。

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.

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

You could check that a lock to the file has been released, and then know that the copying is complete?

这篇关于配置FileSystemWatcher的,这样它提出只有当文件被完全复制创建活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆