如何为FileSystemWatcher设置超时功能?

时间:2013-06-27 11:08:43

标签: c# file filesystemwatcher

如果这个问题太简单,我很抱歉。我是这个主题的新手。

我正在创建一些文件,需要等到它们完成或者直到一段时间过去(这就是我称之为超时)。

FileSystemWatcher非常适合“等到它们完成”,但我看不到一个可以控制其寿命的参数。

使用Tread.Sleep似乎打败了目的(?) - 如果其用法正确,FileSystemWatcher将不存在,我们只会Tread.Sleep while !File.Exists

那么,实现它的最简单方法是什么?感谢。

1 个答案:

答案 0 :(得分:4)

FileSystemWatcher.WaitForChanged Method

MSDN syas

A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor and the time (in milliseconds) to wait before timing out.

相关问题