开发者

reading while open/writing to file in .net?

I notice many applications like firefox allow me to watch part of a video (using VLC) when the file is still do开发者_运维问答wnloading. I would like to do that with my application. When i tried opening the video with VLC i get an error.

How do i allow reading when i write to a file? my open line is

File.Open(fn, FileMode.Append)

i do append so i can resume partial files.


You should use the Open overload, that takes a FileShare parameter:

File.Open(fn, FileMode.Append, FileAccess.Write, FileShare.Read)

This way you explicitly state that other processes are allowed to open the file for reading while you are still writing to it.


You are leaving it up to the Open() method to pick the FileShare value passed to the FileStream constructor. Which is FileShare.None. Specify your own.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜