I am developing a code that will be used by 200 different user's to access a single file.

What would be the best practice for me to read file which is being accessed by large number of users at same time

FileStream stream = File.OpenRead(FileName);
 byte[] contents = new byte[stream.Length];
 stream.Read(contents, 0, (int)stream.Length);
 stream.Close();

Any better way of doing it ?

有帮助吗?

解决方案

You should use an overload method and specify file sharing explicitly (otherwise you will encounter UnauthorizedAccess exceptions, when opening multiple streams):

var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);

As long as its reading only - this should work fine.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top