C# FileStream Dispose

写入一个文件后,马上调用一个函数进行读取处理。

大部分情况下都OK,但是有时候会错误。

Google到stackoverflow上一篇问答里面有模糊的解释:

http://stackoverflow.com/questions/6350224/does-filestream-dispose-close-the-file-immediately


I have some code that writes a file by saving a MemoryStream to a FileStream using MemoryStream.WriteTo(). After the file is closed it is opened up again to read some metdata...

This works about 80 - 90% of the time. The other 20% I get an exception saying the file is "in use by another process".

Does FileStream.Dispose() not release resources synchronously? Is there something going on lower in Win32 land I'm not aware of? I'm not seeing anything obvious in the .Net documentation.

Is this on NTFS? Is the file local or on a remote share? I doubt that it is Dipose() not closing the HANDLE, I think you might be experiencing what the SAMBA developers called Window's "onerous open modes" (especially if a retry of 500-1000ms on the second open succeeds). 


看这个意思,这个和底层文件系统有关?



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值