2013-06-27 52 views
2

如果这个问题太简单了,我很抱歉,我对这个问题很陌生。如何为FileSystemWatcher设置超时功能?

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

FileSystemWatcher对于“等到他们完成”是完美的,但我看不到一个管理其寿命的参数。

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

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

回答

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.