You should be able to useBinaryReader
instead of TextReader
. Just make sure you lock
the array on the thread you access it from (writing).
Object locker = new Object;
lock (locker) {
//BinaryReader here
}
From the other thread(s) use the same:
lock (locker) {
//read from array (read is thread-safe though)
}
If there is a write-operation going on the other thread will wait until the object is unlocked.
You can also use the File.ReadAllBytes
if you don't need to read in chunks.
Alternatively use ASCII or UTF8 encoding with the Textreader.