[英]How to Load Xml file whilelocking it using XDocument.Load() method?
I am using following two code to load an XML.Some other process is updating the same XML while i am trying to Load it.It's giving me below error in both case:- 我正在使用以下两个代码来加载XML。在尝试加载XML时,其他一些进程正在更新相同的XML。在两种情况下,这都给我以下错误:-
The process cannot access the file 'D:\\Projects\\WriteOnXml\\Xml\\test.xml' because it is being used by another process.
该进程无法访问文件'D:\\ Projects \\ WriteOnXml \\ Xml \\ test.xml',因为该文件正在被另一个进程使用。
1) 1)
using (FileStream xml = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
XDocument xdoc = XDocument.Load(xml);
}
2) 2)
using (StreamReader sr = new StreamReader(dest))
{
xdoc = XDocument.Load(sr);
}
I want to load it while it is updating by some other process. 我想在通过其他过程更新它时加载它。 Any better approach.
任何更好的方法。
have a look on that question: c# xml.Load() locking file on disk causing errors 看一下这个问题: 磁盘上的c#xml.Load()锁定文件导致错误
it seems that if you could use xml document it will work... 看来,如果您可以使用xml文档,它将可以正常工作...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.