Blocking Multiple Application accessing the same file
-
Hi , I have two Applications , 1 being a Windows Service and the other one is a Windows Application . Both the Applications access an xml file which has to be modified under different scenarios . I want to avoid concurrent updates /Reads on the xml file from both the application . Tried using the ReadWriteLock for avoiding concurrent access on the file ,but it doesn't seem to work . Kindly suggest how this can be achieved . Thanks in Advance Girija
-
Hi , I have two Applications , 1 being a Windows Service and the other one is a Windows Application . Both the Applications access an xml file which has to be modified under different scenarios . I want to avoid concurrent updates /Reads on the xml file from both the application . Tried using the ReadWriteLock for avoiding concurrent access on the file ,but it doesn't seem to work . Kindly suggest how this can be achieved . Thanks in Advance Girija
CORRECTION: Open the file as FileShare.None[^] (one of the sharing options) - that way nothing else will be able to open the file. e.g.
FileStream stream = new FileStream("C:\MyFile.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None);
Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Hi , I have two Applications , 1 being a Windows Service and the other one is a Windows Application . Both the Applications access an xml file which has to be modified under different scenarios . I want to avoid concurrent updates /Reads on the xml file from both the application . Tried using the ReadWriteLock for avoiding concurrent access on the file ,but it doesn't seem to work . Kindly suggest how this can be achieved . Thanks in Advance Girija
AFAIK the
ReaderWriterLock
is local to a process. You will have to use a namedMutex
, that has system scope and thus can be shared between processes.Regards, Tim