调用XDocument.Root.Add(XElement)时服务冻结

时间:2016-08-15 12:37:02

标签: c# linq-to-xml

我正在开发一项服务,该服务在某个文件夹上运行定期扫描,以收集有关其中的一些文件及其子文件夹的信息。

我已经在控制台应用程序中测试了代码,它按预期运行,但是当它从我的服务运行时,执行似乎卡在它调用scanLog.Root.Add(temp)的部分;

我可以看到“开始添加节点”的事件条目,但它永远不会到“完成添加节点”的任何想法,为什么这在我的服务中不起作用,但在控制台应用程序中工作正常? / p>

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");                 
                }                    
            }
        }



    }

0 个答案:

没有答案