c# Exception The process cannot access the file

前端 未结 5 1618
孤独总比滥情好
孤独总比滥情好 2021-01-13 15:21

I\'m getting an exception: The process cannot access the file.

Here\'s the code:

if (!Monitor.TryEnter(lockObject))
    return;
try
{
    watcher.Ena         


        
5条回答
  •  暖寄归人
    2021-01-13 15:47

    It may be because of the watcher (then FileShare.ReadWrite is the important part).

    Try:

    XmlDocument xdoc = new XmlDocument();
    FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    xdoc.Load(fs);
    

提交回复
热议问题