Problem with Opening Multiple Files At Once

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

Cool Guy

Oh dear, I've gotten myself into a right mess.

The other day my application (one that serves files through sockets) was
opening the file, reading the full contents into memory, then sending that
file to the client.

This cause major system slowdown due to misuse of RAM.

So I rewrote the app to read and send bits of a file at a time, but now I
have another problem: I can't have more than one file open at one time.

How could I get around this?

P.S. I'm using FileStream.

Illustration of the problem:

Client1 requests file X.
....start sending file X...
Client2 requests file X.
....error because it's already open for sending to Client1...

Any help would be very much appreciated.
 
In fact, I just found out how to get around this: specify FileShare.Read as
the share parameter in the FileStream contructor.

Yey!
 
You should be able to open the file in read only mode, which would not put
an exclusive lock on it.
 
Back
Top