- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我们刚刚开始遇到 FileSystemWatcher 的一个奇怪问题,其中对 Dispose() 的调用似乎挂起。这段代码已经运行了一段时间没有任何问题,但我们刚刚升级到 .NET3.5 SP1,所以我想看看是否有其他人看到过这种行为。下面是创建 FileSystemWatcher 的代码:
if (this.fileWatcher == null)
{
this.fileWatcher = new FileSystemWatcher();
}
this.fileWatcher.BeginInit();
this.fileWatcher.IncludeSubdirectories = true;
this.fileWatcher.Path = project.Directory;
this.fileWatcher.EnableRaisingEvents = true;
this.fileWatcher.NotifyFilter = NotifyFilters.Attributes;
this.fileWatcher.Changed += delegate(object s, FileSystemEventArgs args)
{
FileWatcherFileChanged(args);
};
this.fileWatcher.EndInit();
它的使用方式是更新 TreeNode 对象的状态图像(略微调整以删除业务特定信息):
private void FileWatcherFileChanged(FileSystemEventArgs args)
{
if (this.TreeView != null)
{
if (this.TreeView.InvokeRequired)
{
FileWatcherFileChangedCallback d = new FileWatcherFileChangedCallback(FileWatcherFileChanged);
this.TreeView.Invoke(d, new object[]
{
args
});
}
else
{
switch (args.ChangeType)
{
case WatcherChangeTypes.Changed:
if (String.CompareOrdinal(this.project.FullName, args.FullPath) == 0)
{
this.StateImageKey = GetStateImageKey();
}
else
{
projectItemTreeNode.StateImageKey = GetStateImageKey();
}
break;
}
}
}
}
我们是否遗漏了什么,或者这是 .NET3.5 SP1 的异常?
最佳答案
只是一个想法...这里是否有可能存在死锁问题?
您正在调用 TreeView.Invoke,这是一个阻塞调用。如果在您单击导致 FileSystemWatcher.Dispose() 调用的任何按钮时发生文件系统更改,您的 FileWatcherFileChanged 方法将在后台线程上调用并调用 TreeView.Invoke,这将阻塞直到您的表单线程可以处理 Invoke 请求.但是,您的表单线程将调用 FileSystemWatcher.Dispose(),它可能不会返回,直到处理完所有未决的更改请求。
尝试将 .Invoke 更改为 .BeginInvoke,看看是否有帮助。这可能会帮助您指明正确的方向。
当然,也可能是.NET 3.5SP1 的问题。我只是根据您提供的代码在这里推测。
关于c# - FileSystemWatcher Dispose 调用挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73128/
是否可以使用 FileSystemWatcher 查找正在更改文件的 PID 或进程名称? 最佳答案 不,您需要一个文件系统过滤器驱动程序来跟踪具有此类详细信息的更改。 关于filesystemwat
我有一个项目可以监视当前由 Windows Server 计算机托管的网络共享上的文件创建/删除事件,但我正在考虑将文件移动到运行 DataOntap 的 NetApp 机器上。他们的 API 文档说
我正在尝试跟踪文件系统的更改。因此我使用 FileSystemWatcher。不幸的是,Renamed 事件在 Windows 7 和 Windows 8 上不提供 oldName 信息。在 Wind
当我尝试监视网络路径上的文件夹(DFS - 分布式文件系统)时出现异常 System.IO.Internal.BufferOverflowException: To many changes at o
我想问一下是否有可能忽略由自己的进程 FileSystemWatcher 生成的文件系统更改事件正在运行。例如,我自己的进程在监视目录中创建了一个文件,并且FileSystemWatcher 应该认识
我正在使用 FileSystemWatcher 来监控文档扫描到的文件夹。当检测到新文件时,它会发送电子邮件通知某人。它按原样工作,但有时(不是每个文件)它会在新文件上触发 2 或 3 次,并为同一文
FileSystemWatcher 事件可以触发多次。如果我的代码需要可预测的行为,那就不好了。 这在 MSDN documentation 中有描述: Common file system oper
我在 Ubuntu VM 上有一个 dnx 控制台应用程序,它监视与主机操作系统(Windows 8.1)共享的文件夹。当 Ubuntu VM 上的共享文件夹中发生文件更改时,控制台应用程序会响应它们
我需要在我将使用 FileSystemWatcher 的文件夹中记录文件的创建或复制/移动事件。问题是,当我将一个文件粘贴到文件夹中时,FileSystemWatcher 将引发一个 Created
有些东西让我很感兴趣,我没有找到任何资源。 FileSystemWatcher 如何知道计算机“A”上的文件何时创建/删除/更改/重命名? 我认为这适用于轮询(观察者轮询服务器以检查更新),但在使用
我有一个正在监视新文件创建的文件夹。创建文件后,运行的任务可能需要5到30分钟。当最后一个文件仍在处理中时,通常可以创建一个新文件。 从一些测试案例来看,似乎有一些任务队列。有没有办法允许任务同时运行
您好,我正在创建一个 Windows 服务来监视某些目录,以查看目录的大小是否已达到其限制。我创建了一个文件系统观察器,如下所示: FileSystemWatcher watc
我设置了一个 FileSystemWatcher 来检查新文件、将内容存储在数据库中并删除文件。大约10天前,它开始忽略一些文件。我们讨论的是总共 50,000 个文件中的 1,500 个文件。通过手
我在代码中使用 FileSystemWatcher 来跟踪受监视目录下文件的任何更改/重命名/添加。现在,如果受监控的目录本身被删除,我需要一个通知。 关于如何实现这一目标有什么建议吗? 我试图在父目
您好,我正在创建一个 Windows 服务来监视某些目录,以查看目录的大小是否已达到其限制。我创建了一个文件系统观察器,如下所示: FileSystemWatcher watc
我目前正在为 OpenFOAM 输出文件实现文件内容观察器。这些文件由 OpenFOAM 在 Unix 环境中编写,并由我在 Windows 环境中的应用程序使用。 请考虑我的第一个工作收敛文件观察者
我写了下面的代码。 [XmlRoot("myxml")] public class myxml { [XmlElement("one")] public string one { g
我过去使用过 FileSystemWatcher。但是,我希望有人可以解释它在幕后的实际运作方式。 我计划在我正在制作的应用程序中使用它,它将监控大约 5 个驱动器和可能 300,000 个文件。 F
如何用 C# 将文件写入 FileSystemWatcher 监视的文件夹路径? 我的fileSystemWatcher设置如下: public FileSystemWatcher CreateAnd
我有以下代码用于监视文本文件的目录,该目录每天两次获取新文件,该代码在一段时间内工作正常但之后它停止触发 OnCreated 事件... [PermissionSet(SecurityAction.D
我是一名优秀的程序员,十分优秀!