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)
}
Now, this class is been used by multiple projects(Services) which in turn are combined in to a single project.
Can i use STATIC lock object in a class and will it work in this case of different processes??
So there are possibility that they use the file at same time and at times it gives me the error that different thread owns the file although i've kept the LOCK.
what could be the best solution in this senario? Please guide.
How about this link ...
Is there a way to check if a file is in use?
is this the best way to go for or i should go with Mutex??
Please guide..