apocalypse
apocalypse

Reputation: 5884

Many FileStream's attached to one file

Like in title:

FileStream fs  = new FileStream ("test.mkv", FileMode.Open);
FileStream fs1 = new FileStream ("test.mkv", FileMode.Open);

It throw an error: The process cannot access the file '...' because it is being used by another process.

But why, if it is opened for read only (?). If not, how to open file as read only?

Upvotes: 0

Views: 63

Answers (1)

Samuel Neff
Samuel Neff

Reputation: 74949

You need to specify that you're opening it read only and that you're sharing it.

var fs1 = new FileStream("test.mkv", FileMode.Open, FileAccess.Read, FileShare.Read);
var fs2 = new FileStream("test.mkv", FileMode.Open, FileAccess.Read, FileShare.Read);

Upvotes: 5

Related Questions