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;
}

Do I need to lock the file because this method is called from worker
threads? I mean, would reading the same
file more than once at the same time cause problems?

Re: Reading Files in Worker Threads by Alvin

Alvin
Wed Sep 08 21:34:59 CDT 2004

no, not usually. if you need to write to the file you will need to lock.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Cool Guy" <coolguy@abc.xyz> wrote in message
news:rcpa0k24fys6.dlg@cool.guy.abc.xyz...
>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;
> }
>
> Do I need to lock the file because this method is called from worker
> threads? I mean, would reading the same
> file more than once at the same time cause problems?



Re: Reading Files in Worker Threads by Cool

Cool
Thu Sep 09 02:28:56 CDT 2004

Alvin Bruney [MVP] wrote:

> no, not usually. if you need to write to the file you will need to lock.

Thanks.