Problem with Opening Multiple Files At Once

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.
 
C

Cool Guy

In fact, I just found out how to get around this: specify FileShare.Read as
the share parameter in the FileStream contructor.

Yey!
 
M

Marina

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top