即使FileWatcher应该在UNC上工作,我也遇到了很多问题。由于你的问题不是时间关键的,我会创建一个线程来检查文件是否存在,睡眠几秒钟循环,直到发送警报的文件消失。
注意:作为服务运行需要正在运行的用户对远程共享拥有网络权限。
更新:刚在我们的网络上做了一个快速测试。运行Windows 7 R2服务器的客户端运行Windows 2008 R2。增加了几个文件,无论是小型还是大型文件。在代码运行时删除文件没有任何问题。即使没有了Thread.Sleep
bool filesDeleted = false;
while (!filesDeleted)
{
DirectoryInfo di = new DirectoryInfo(@"\\server\share\path\");
FileInfo[] files = di.GetFiles();
foreach (var file in files)
{
DateTime created = file.CreationTime;
string fileName = file.Name;
//Do what every you need to check if the two files are still there
}
Thread.Sleep(5000);
}
//Send alert
“我发现该文件已在使用FileWatcher被锁定” - 似乎不大可能.... – 2011-02-28 05:17:32
你处理文件,同时通过filewatcher监控。您需要在应用程序中优雅地关闭文件句柄。 – 2011-02-28 05:49:12
发布您的代码 - 当您有新文件时,您会做什么? – VinayC 2011-02-28 06:00:38