I was wondering if i could safely read from an XmlDocument object using SelectNodes() and SelectSingleNode() from multiple threads with no problems. MSDN says that they are
SelectNodes / SelectSingleNode should be safe (they only read data). Of course you need to synchronize those with any method that actually modifies the xml.
As you are going to write/read to/from the XML document you need to synchronize those two operations if you don't want to run into race conditions. And if you care about performance (who doesn't?) a ReaderWriterLockSlim might perform better than locking.
Here's the deal. If the documentation says that instance methods are not guarenteed to be threadsafe then you better take note. And if you do decide to use the class in a multithreaded scenario without the proper synchronization mechanisms then you need to be 1) aware the consequences of ignoring the documentation and 2) prepared for all of your assumptions to be invalidated on future versions of the class. This advice is valid even for methods that seem to only be reading internal state.
How do you know that SelectNodes and SelectSingleNodes do not modify an internal variable? Because if they do then they are definitely not threadsafe! Now, I happen to use Reflector to look inside and I can see that they do not modify any internal variables. But, how do you know that would not change in a future version?
Now, since we know in reality that SelectNodes and SelectSingleNodes do not modify the internal state of the class they may be safe for multithreaded operations despite the warning if and only if the following conditions apply.
My advice...take the warning in the documentation literally and use the appropriate synchronization mechanisms.
you could also use MsXml FreeThreadedDOMDocument model instead of the classical DomDocument when you call createInstance.
Beware that according this article, FreeThreadedDOMDocument is 7x or 10x slower than classical DomDocument.