Ler e gravar no arquivo ao mesmo tempo

para um aplicativo que usa um arquivo como algum tipo de armazenamento global para reservas de dispositivos em uma empresa, preciso de uma maneira de ler e gravar em um arquivo (ou de bloquear um arquivo, ler a partir dele, gravá-lo e desbloqueá-lo). Um pequeno trecho de código vai filmar o que quero dizer:

FileStream in = new FileStream("storage.bin", FileMode.Open);
//read the file
in.Close();

//!!!!!
//here is the critical section since between reading and writing, there shouldnt
//be a way for another process to access and lock the file, but there is the chance
//because the in stream is closed
//!!!!!
FileStream out = new FileStream("storage.bin", FileMode.Create);
//write data to file
out.Close();

isso deve ter algo parecido com isto

LockFile("storage.bin");
//read from it...
//OVERwrite it....
UnlockFile("storage.bin");

o método deve ser absolutamente seguro, já que o programa deve rodar em 2000 dispositivos ao mesmo tempo

questionAnswers(5)

yourAnswerToTheQuestion