I have deployed ASP.NET web site and ASP.NET web service on the same web server. Both of them require access to shared file.
How to implement/share lock that supports single writers and multiple readers? If somebody reads, nobody can write, but all still can read. If somebody writes, nobody can read/write.
to open file for writing with allowing other threads to read it use System.IO.File.Open method with System.IO.FileShare.Read. Ie.:
Other (reading) threads should use System.IO.FileAccess.Read
Signature of Open method:
UPDATE If you need all instances to ocasionally write to file. Use Mutex class to reserve file writing. Ie.:
Hope it helps.