FileSystemWatcher的工作就完成了? [英] FileSystemWatcher Work is Done?

查看:217
本文介绍了FileSystemWatcher的工作就完成了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置一个FsWatcher上的本地文件系统的目录。我只是想知道,当文件被添加到目录中,以便它们可以被移动到另一个文件系统。我似乎能够检测何时所述第一文件是在,但实际上我想知道当从给定的复制操作中的所有文件都完成。

I setup a FsWatcher on a local filesystem directory. I only want to know when files are added to the directory so they can be moved to another filesystem. I seem to be able to detect when the first file is in, but actually I want to know when all files from a given copy operation are done.

如果我使用Windows资源管理器从一个目录复制到另一个文件,浏览器会告诉我,有n秒留在了转移,因此,虽然有一些活动的开始转移,并最终转移的每个文件,似乎有什么东西在开始传输和终端传输的所有文件。

If I used Windows Explorer to copy files from one directory to another, Explorer would tell me that there are n seconds left in the transfer, so while there is some activity for the begin-transfer and end-transfer for each file, it appears that there is something for the begin-transfer and end-transfer for all files.

我不知道是否有类似的事情,我可以使用.NET Framework做到这。我想知道,当所有文件中,而不是在一个交易只是一个单一的文件。如果还有什么烤,也许我应该拿出某种等待/为了对付只做我的活动时,一个工作就是完成。

I wonder if there is something similar that I can do just with the .NET Framework. I would like to know when "all" files are in and not just a single file in a "transaction". If there is nothing baked in, maybe I should come up with some kind of waiting/countering in order to only do my activity when a job is "done".

不知道,如果我在这一个做100%意义上说,请人评论。

Not sure if I'm making 100% sense on this one, please anyone comment.

感谢。

推荐答案

我在过去实现这一点的办法是有一个'标记'文件与一个特殊的名字,例如: '结束'。此文件始终写入的最后一个文件,并作为当多文件交易完成的指示。这会工作得很好,如果有被写这些文件集,只有一个线程。

The way I have implemented this in the past is to have a 'marker' file with a special name, e.g. 'end'. This file is always the last file written and serves as an indicator for when a multi file transaction is complete. This would work just fine if there is only one thread which is writing these sets of files.

如果有很多线程,每个线程都可以写一组文件,那么你就需要以某种方式每个结束文件与设置文件是标记的关联。这样做的一种方法是将包括一个GUID(或一些其他唯一标识符)的文件名,例如

If there are many threads, each of which may be writing a set of files, then you'd need to somehow associate each 'end' file with the set of files it is marking. One way to do this would be to include a GUID (or some other unique identifier) in the filenames, e.g.

{ GUID1 的.file1.bin, GUID1 的.file2.bin, GUID1 的.END}

{ GUID1.file1.bin, GUID1.file2.bin, GUID1.end }

{ GUID2 的.file1.bin, GUID2 的.file2.bin, GUID2 的.END}

{ GUID2.file1.bin, GUID2.file2.bin, GUID2.end }

另一种方式做到这一点是从每一组中的所有文件压缩成一个ZIP文件,所以你只需要留意单个文件。

Another way to do it is to zip all the files from each set into a single ZIP file so you only have to watch for single files.

这篇关于FileSystemWatcher的工作就完成了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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