6

This is probably a really simple thing, but I haven't been able to find it, and I'm probably just searching for the wrong thing...

XmlTextReader --> Does it lock the file you're reading? I'm using reader.Read() and that's about it.

1 Answer 1

20

When you create a new XmlTextReader providing a string, it will lock the file with a write lock (but not a read lock); however, if you provide it a Stream, it would depend on the stream itself.

FileStream stream = new FileStream(@"myfile.xml", FileMode.Open,
                            FileAccess.Read, FileShare.ReadWrite);
XmlTextReader reader = new XmlTextReader(stream);

You can now read without having a lock.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 beat me to the answer. Can also do FileStream stream = File.Open(...)
Yeah, same difference. One probably calls the other (which I don't know, but you could find out with Reflector.)
Thank you, you are the reason I can finally go to sleep tonight :-) Previously I tried async read, reader.dispose(), none worked. thank you Good night everybody

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.