如何为FileSystemWatcher设置超时功能
本文关键字:超时 功能 设置 FileSystemWatcher | 更新日期: 2023-09-27 18:20:10
如果这个问题太简单,我很抱歉,我是这个主题的新手。
我正在创建一些文件,需要等待它们完成,或者等待一段时间过去(这就是我所说的超时)。
FileSystemWatcher
非常适合"等到它们完成",但我看不到一个参数可以控制它的寿命。
使用Tread.Sleep
似乎违背了目的(?)——如果它的用法正确,FileSystemWatcher
就不会存在,我们只会存在Tread.Sleep while !File.Exists
。
那么,实现它的最简单正确的方法是什么呢?谢谢
FileSystemWatcher.WaitForChanged方法
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.