What I'm trying to do with FileStreamin C # /. NET, is to open two streams: one application for the file, and the other is reading asynchronously (for unit testing the network connection processing code). I can’t figure out how to make the write stream open the file without exception, and therefore the code always throws an exception:
The process cannot access the file 'C: \ test.txt' because it is being used by another process.
Here is some code that demonstrates the problem:
FileStream fwriter = new FileStream("C:\\test.txt", FileMode.Append,
FileAccess.Write, FileShare.Read);
FileStream freader = new FileStream("C:\\test.txt", FileMode.Open,
FileAccess.Read, FileShare.Read);
source
share