FileNotFoundException异常在FileSystemWatcher的 [英] FileNotFoundException in FileSystemWatcher

查看:328
本文介绍了FileNotFoundException异常在FileSystemWatcher的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个目录使用 FileSystemWatcher的并添加了事件处理程序,将其 EnableRaisingEvents = TRUE; IncludeSubdirectories = FALSE; 并添加 NotifyFilters

I am using a FileSystemWatcher on a directory and added its event handlers, set its EnableRaisingEvents=true; and IncludeSubdirectories=false; and added NotifyFilters.

在运行应用程序,如果我在指定目录下创建新的文件夹有时我得到

While running the application if I create new folders in the specified directory sometime I get

FileNotFoundException异常:当读取一个目录出现的错误。   System.IO.FileSystemWatcher.StartRaisingEvents()   System.IO.FileSystemWatcher.set_EnableRaisingEvents(布尔值)

FileNotFoundException : "An error occurred while reading a directory". System.IO.FileSystemWatcher.StartRaisingEvents() System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)

什么是问题的根源在哪里?

What can be root cause of the problem?

什么是 StartRaisingEvents()

推荐答案

这是典型的因为 FileSystemWatcher的可能是不可靠的。该文件夹可能不是完全当你的事件存在。您可能需要重试足够的停顿,做各种 Directory.Exists()在实际执行IO操作检查。

This is typically because the FileSystemWatcher can be unreliable. The folder may not "fully" exist when you get the events. You may need to retry with sufficient pauses and do various Directory.Exists() checks before actually performing IO operations.

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

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