监视映射的 UNC 时 FileSystemWatcher() 问题
我对 FileSystemWatcher() 类有疑问。当我监视硬盘上的本地文件时,它可以完美地工作。当我更改为映射的 UNC 时,它不再触发。 UNC 通过提供用户和密码的 NET USE 命令映射到本地驱动器 (X:),这是在启动时在批处理文件中完成的。任何人都知道为什么这不起作用?我已经检查了路径,所有路径都是正确的,因此问题应该与其他内容有关...
fw = new FileSystemWatcher();
fw.Path = fileInfoPath;
fw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fw.Filter = fileInfoName;
fw.Changed += new FileSystemEventHandler(FileOnChanged);
fw.Created += new FileSystemEventHandler(FileOnChanged);
感谢帮助! :)
I have a problem with the FileSystemWatcher() Class. It works flawlessly when I'm monitoring a local file on my harddrive. When I change to a mapped UNC, it does not fire anymore. The UNC is mapped to a local drive (X:), with the NET USE command where the user and password are supplied, this is done in a batch file at startup. Anyone that knows why this doesn't work? I have checked the paths, all of them are correct, so the problem should be related to something else...
fw = new FileSystemWatcher();
fw.Path = fileInfoPath;
fw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fw.Filter = fileInfoName;
fw.Changed += new FileSystemEventHandler(FileOnChanged);
fw.Created += new FileSystemEventHandler(FileOnChanged);
Help appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对这个问题的解决方案是离开 FileSystemWatcher() 并创建我自己的小观察程序。这很简单,但我唯一想看的是文件何时被重写,然后执行一些操作。
这基本上就是我所做的(删除了 try/catch 和一些其他线程的调用):
My solution to the problem was to leave the FileSystemWatcher() and create my own little watcher. It's very simple, but the only thing I wanted to watch was when the file was rewritten and then perform some action.
This is basically what I do (removed try/catch and some invoking of other threads):
我发现了一种非常酷的方法,可以在 codeproject 的 Windows 服务中使用 FileSystemWatcher 的凭证来获取 UNC。
请参阅 Adrian Hayes 帖子:http://www. codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials
他的解决方案非常有效。
I found a really cool way to get UNC with credentials working with FileSystemWatcher in a windows service on codeproject.
see Adrian Hayes post: http://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials
His solution works a treat.
我无法让任何日期和时间触发器起作用。查看文件详细信息,服务器根本没有更改它们。因此,我使用了文件大小触发器(NotifyFilters.Size),这很有用。我留下了其他通知,以防万一我不使用 UNC。
I couldn't get any of the date and time triggers to work. Looking at the file details the server wasn't changing them at all. So instead I used a trigger on the file size (NotifyFilters.Size) which worked a charm. I left the other notifies in just in case I'm not using a UNC.