我正在處理某個文件夾上運行定期掃描的服務,以收集有關其中的某些文件及其子文件夾的信息。調用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