473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XmlDocument.Save() does not close the file

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

Mar 14 '06 #1
0 1879

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Pearson | last post by:
I have created an XmlDocument and can see that this is correctly formed and has a root element If I Save the doc to a file and reload it all works o If I dump the doc to a stream, again using the...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
1
by: Shawn | last post by:
Hi. I'm using a FileStream (instead of just the path to the xml file) to load an XmlDocument. I'm doing this because I need to be able to prevent other processes to update the file I'm working on....
1
by: Casper JH Erasmus | last post by:
How do I save the contents of a TreeView to a XML Document?
4
by: Roshawn Dawson | last post by:
Hi, I don't know why, but I can't seem to get this to work: Public Sub DoSomething() Dim sb as New StringBuilder() sb.Append("http://webservices.amazon.com/onca/xml?")...
2
by: feng | last post by:
I think I didn't phrase my quetion clear enough in the last post. Here is what I need: In my VB.Net code, I already have a XML created in XMLDocument formate. I can also convert it into a string...
1
by: liuhengyi | last post by:
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 from...
3
by: Stephen Ward | last post by:
I have a simple little project open a xml file change a few nodes save the file, no big deal. The problem is that the doctype is getting modified when I save the file. So it looks like this:...
0
by: dthope69 | last post by:
I have a client that is requiring my web service to accept XMLDocument object as input parameter. I had created it initially to accept byte string and it worked fine. However, when changing to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.