c# - File.Open 跨线程编写

标签 c# stream binaryformatter

跨多个线程打开文件并向其写入流是否安全?如果不是,我可以采取什么措施来确保安全?

最佳答案

不,标准 FileStream 不是线程安全的。

您应该使用 var safe = Stream.Synchronized(File.Open(...)); 来创建线程安全的包装器。

Stream.Synchronized() on MSDN

关于c# - File.Open 跨线程编写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16526652/

相关文章:

c# - ASP.NET MVC 默认路由错误

c++ - 使用 std::streams 格式化输出

c# - 使用 BinaryFormatter 而不是 protobuf-net 的原因

c# - 仅安装更新的框架时应用程序会运行吗

c# - 尝试使用 WebClient 下载 URL 中包含 ':' 的文件

c# - WCF 引用出现 "Service_References"命名空间

iphone - iOS-开发iPhone应用程序以将相机视频流式传输到计算机吗?

python - 如何连续改变正弦声音的频率?

c# - 性能:BinaryFormatter 与 XmlSerializer

c# - 使用 BinaryFormatter 序列化和反序列化对象图