Reading File in Background Threads

  • Thread starter Thread starter Cool Guy
  • Start date Start date
C

Cool Guy

I use the following method to read a file:

static byte[] ReadFile(string path)
{
FileStream stream = new FileStream(path, FileMode.Open);
BinaryReader reader = new BinaryReader(stream);
byte[] result = reader.ReadBytes((int)stream.Length);
reader.Close();

return result;
}

This method might be called rapidly many times, becuase it is called from
worker threads.

Do I need to lock the file because of this? I mean, would reading the same
file at the same time cause problems?
 
Hi
i think as long as you are not writing anything back ( no modification is
done on the file ) then , this should not cause any problem .
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Mohamoss said:
i think as long as you are not writing anything back ( no modification is
done on the file ) then , this should not cause any problem .

Thanks.
 
Back
Top