背景信息:我正在使用服务中实现的 FileSystemWatcher 类来监视文件中的更改。这是触发 onCreate 事件时引发参数异常(路径不是合法形式)的编码部分。
FileMonitor.CS
public partial class FileMonitor:ServiceBase
{
public FileSystemWatcher Watcher = new FileSystemWatcher();
Private void FileWatcher()
{
FileActionHandler ActionHandler = new FileActionHandler();
Watcher.Created += new FileSystemEventHandler(ActionHandler.onCreate);
Watcher.Deleted += new FileSystemEventHandler(ActionHandler.onDelete);
Watcher.Renamed += new RenamedEventHandler(ActionHandler.onRenamed);
Watcher.EnableRaisingEvents = true;
}
}
FileActionHandler.CS
class FileActionHandler
{
FileMonitor FileMon = new FileMonitor();
public void onCreate/onRename/onDelete(object source, FileSystemEventArgs e)
{
try
{
FileMon.Watcher.EnableRaisingEvents = false;
}
catch
{
/* Exception Code */
}
finally
{
FileMon.Watcher.EnableRaisingEvents = true;
}
}
}
问题:谁能告诉我为什么抛出异常以及如何解决它?