我正在处理某个文件夹上运行定期扫描的服务,以收集有关其中的某些文件及其子文件夹的信息。调用XDocument.Root.Add(XElement)时服务会冻结
我已经测试了控制台应用程序中的代码,它按预期运行,但是当它从我的服务运行时,执行似乎停留在它调用scanLog.Root.Add(temp)的部分;
我可以看到说“开始添加节点”的事件条目,但是它永远不会到达“完成添加节点”的任何想法,为什么这不起作用在我的服务中,但在控制台应用程序中正常工作?
private void ScanForChildCopies(string dir)
{
foreach(var dirs in Directory.GetDirectories(dir))
{
ScanForChildCopies(dirs);
}
foreach(var files in Directory.GetFiles(dir, "*.ac"))
{
FileInfo fInfo = new FileInfo(files);
serviceLogging.WriteEntry("Found File: " + files);
if (fInfo.Exists)
{
if ((DateTime.Now - fInfo.LastWriteTime).Days > 0)
{
serviceLogging.WriteEntry("Building node");
XElement temp = new XElement("childfile", new XElement("name", fInfo.Name), new XElement("lastmodified", fInfo.LastWriteTime.ToShortDateString()),
new XElement("age", (DateTime.Now - fInfo.LastWriteTime).Days.ToString()));
serviceLogging.WriteEntry("Starting to add node");
scanLog.Root.Add(temp);
serviceLogging.WriteEntry("finished Adding node to scanlog");
}
}
}
}
当试图将XElement(temp)添加到现有XDocument中时挂起,因此在此阶段没有写入实际文件,它应该只是在内存中构建xml并将其添加到XDocument对象。 – Vladmere
当你说服务,你指的是在IIS或Windows服务托管的Web服务... – MrPink13
@Umair Farooq我知道的事实,即IIS将重置应用程序池,如果你写入任何东西到映射文件夹中...我只是简单地指出这可能发生在Vladmere的情况下...... – MrPink13