FileStream locking a file for reading and writing
I have the following code block which is giving me a headache. Logically it should work as I am using the filestream providing the lock within the using statement. When it gets to the line that creates the StreamWriter, it fails saying "the file is not writable". Now my program is a multithreaded application. Any thread could be trying to write to this file. I need the program to lock the file, read the contents, check the contents, then write back any changes. During that process, no other thread should be able to access that file. using (var fs = File.Open(fileLoc, FileMode.Open, FileAccess