I am using an XML file to store the values. This XML file can be accessed from multiple methods.
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)
}
This class is used by many other classes and some times it throws System.IO exception, the file is already used by other process , although I have used the lock statement
Please guide.
If you need this to be safe across multiple instances of the class, you need to make your private locking variable
static.