L
liuhengyi
Hi,
I have a test program that creates 5 threads and each thread uses
XmlDocument.Save(filename) to save a Xml dom to a file. I have put the
lock statement around the Save to prevent concurrent update. However
I'm still seeing the error "System.IO.IOException: The process cannot
access the file "c:\file1.xml" because it is being used by another
process." Am I missing something?
public class XmlTest
{
private static void ThreadProc(object o)
{
XmlDocument x1 = new XmlDocument();
x1.AppendChild(x1.CreateElement("test"));
while (running)
{
lock (typeof(XmlTest))
{
try
{
x1.Save(@"c:\file1.xml");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
//...
}
Thanks,
-hengyi
I have a test program that creates 5 threads and each thread uses
XmlDocument.Save(filename) to save a Xml dom to a file. I have put the
lock statement around the Save to prevent concurrent update. However
I'm still seeing the error "System.IO.IOException: The process cannot
access the file "c:\file1.xml" because it is being used by another
process." Am I missing something?
public class XmlTest
{
private static void ThreadProc(object o)
{
XmlDocument x1 = new XmlDocument();
x1.AppendChild(x1.CreateElement("test"));
while (running)
{
lock (typeof(XmlTest))
{
try
{
x1.Save(@"c:\file1.xml");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
//...
}
Thanks,
-hengyi