- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题不太可能帮助任何 future 的访客;它只与一个小地理区域、一个特定时刻或一个非常狭窄的情况相关,而这些情况通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visit the help center .
9年前关闭。
我想使用文件系统观察程序并在文件更改但触发 onchaged 事件时在表单上显示更改的信息但它被触发两次而不是一次并且我想要显示的表单从不显示并且程序停止而不显示任何异常它都会停止调试
public void Run()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = pathOfPatientFixedFile.Remove(pathOfPatientFixedFile.IndexOf("PatientFixedData.xml")-1);
watcher.Filter = "PatientFixedData.xml";
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.EnableRaisingEvents = true;
}
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
try
{
GetPatientInfo(e.FullPath);
frmPatientInfoDisplay displayPatientInfo = new frmPatientInfoDisplay(_patientInfo);
displayPatientInfo.Show();
}
catch (Exception ex)
{
}
}
private void GetPatientInfo(String filePath)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
using (StreamReader sr = new StreamReader(filePath, Encoding.Default))
{
String line = sr.ReadToEnd();
if (line.IndexOf("<IsPatientFixed>") > 0)
{
var value = GetTagValue(line, "<IsPatientFixed>", "</IsPatientFixed>");
if (value == "true" || value == "True")
{
if (line.IndexOf("<PatientID>") > 0)
_patientInfo[0] = GetTagValue(line, "<PatientID>", "</PatientID>");
if (line.IndexOf("<PatientName>") > 0)
_patientInfo[1] = GetTagValue(line, "<PatientName>", "</PatientName>");
if (line.IndexOf("<PatientSex>") > 0)
_patientInfo[2] = GetTagValue(line, "<PatientSex>", "</PatientSex>");
if (line.IndexOf("<PatientDateOfBirth>") > 0)
_patientInfo[3] = GetTagValue(line, "<PatientDateOfBirth>", "<PatientDateOfBirth>");
}
}
}
}
catch (Exception ex)
{
}
}
最佳答案
首先,您误用了 FileSystemWatcher
因为它是一次性组件——它应该存储在一个字段中,而不是一个局部变量中,并在不再需要时丢弃。
因为您没有存储长期存在的引用,所以它可能正在被垃圾收集,这可能会导致调试停止。
此外,它可能会触发多次,具体取决于与文件交互的任何其他程序对文件执行的操作 - 并且不能保证在您收到通知时您的程序可以访问该文件。
正如评论中所提到的,您确实需要 a) 实现您的 TODO,或 b) 删除这些空的 catch
block (更好的选择,IMO)。你说“没有抛出异常”,但你现在很难检测到。让程序因一个丑陋的错误而崩溃会好得多。
关于c# - FileSystemWatcher 触发两次,程序突然停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12104363/
是否可以使用 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
我是一名优秀的程序员,十分优秀!