Difference between XDocument.Load and FileInfo while processing the file from multiple processes
<p>I am using an XML file to store the values. This XML file can be accessed from multiple methods as well as multiple processes are calling these methods.</p>

<pre><code>Private object lockObject = new object()  
Method1 
 {    
  Lock(this.lockObject)   
  {     
     MyCommonMethod()
  }
 }  

Timer.ElapseEvent
{     
   Lock(this.lockObject)  
    {       
      MyCommonMethod()  
    }  
}     

  MyCommonMethod() 
  {  
     // Read/Write to XML file. 
     var element = XElement.Load(path); 
     // some operations    
     element.save(path) 
 }  
</code></pre>

<p>To avoid the multiple processes to use the same file there are 2 suggestions.
1. Use FileShare.None to lock the file itself. So using that will throw exception if other process is using the file.</p>

<p><a href="http://stackoverflow.com/questions/10039108/best-way-to-read-write-to-file-when-it-is-being-used-across-multiple-app-domains/10083471#10083471">Best way to read\write to file when it is being used across multiple app domains</a></p>

<p><strong>Now, my question is my current code is also throwing the same exception that another thread is using the file.</strong></p>

<p>so what is the difference between XDocument.Load\save and FileInfo with FileShare.None.</p>

<p>Second option is to use Mutex.</p>

<p>Please guide which solution i shd use.</p>
