c# - C# Filesystemwatcher 没有带有网络路径的事件
问题描述
我有以下问题:我制作了一个小型 C# 程序,它使用 FileSystemWatcher 来监视文件夹并在文件更改时执行请求。使用本地路径,一切正常。但是,如果我现在将路径更改为网络路径,则不会再触发任何事件。
我使用网络路径作为 UNC 路径并将路径映射到驱动器号。两者结果相同。FilesSystemWatcher 没有给出错误,但也没有触发事件。
我使用以下代码来初始化观察者
static void Main(string[] args)
{
try
{
var filewatcher = new FileSystemWatcher(@"\\FILESERVER\Test");
filewatcher.NotifyFilter = NotifyFilters.FileName
| NotifyFilters.LastWrite;
filewatcher.Changed += OnChanged;
filewatcher.Error += OnError;
filewatcher.Filter = " *.*";
filewatcher.IncludeSubdirectories = true;
filewatcher.EnableRaisingEvents = true;
filewatcher.InternalBufferSize = 64*1024;
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine($"Changed:");
if (isFileLocked(new FileInfo(e.FullPath)) )
{
return;
}
Console.WriteLine($"Changed: {e.FullPath}, {e.ChangeType}");
//CreateOrUpdate(e.FullPath);
}
private static void OnError(object sender, ErrorEventArgs e) =>
PrintException(e.GetException());
private static void PrintException(Exception ex)
{
if (ex != null)
{
Console.WriteLine($"Message: {ex.Message}");
Console.WriteLine("Stacktrace:");
Console.WriteLine(ex.StackTrace);
Console.WriteLine();
PrintException(ex.InnerException);
}
}
解决方案
推荐阅读
- android - 无法解决:com.android.support.cardview-v7:28.0.0:
- scala - 了解 IO 单子
- mysql - 为什么游标在过程中取空?
- wordpress - 在同一个 EC2 实例和同一个端口上托管 2 个不同的网站
- powerbi - Power BI API - 按 ID 获取数据集
- android - 反向 AppBarLayout.ScrollingViewBehavior
- r - 将 SAS Proc Shewhart 转换为 R 编程
- php - mysqli_get_client_stats 是否向 sql server 发送请求
- printing - 修改与 gwbasic 一起使用的基本文件
- sql - 使用 django ORM 转换数据