c# - 两个控制台程序从 C# 中的同一文件中读取内容
问题描述
我已经编写了用于读取文件内容的控制台应用程序(文件位于共享网络上)。文件以读取模式打开并授予权限,如下所示,
FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader reader = new StreamReader(stream);
var E51300Index = reader.ReadLine();
然后这个控制台应用程序安装在多台机器(共享网络)上,并尝试从不同的机器同时访问。
不允许并行访问及其抛出错误,
Process cannot access the file
xxx.txt because it is being used by another process
是否有任何解决文件不锁定/并行访问的方法。
提前致谢!
解决方案
推荐阅读
- c# - 如何将 NameValueCollection 转换为 IEnumerable
> 表单值? - r - 使这个树状图工作需要什么?
- python - 我可以使用分块将巨大的 .csv 文件转换为 .ftr 吗?
- dictionary - 如何使用 Julia 中字典字典中的数据绘制图形?
- tfx - 气流:如何使用 tfx 的 AirflowDagRunner 在运行时为 tfx 管道创建分布式气流中的虚拟 python 环境?
- php - EasyAdminBundle,configureUserMenu界面别让我回
- database - 使用 tableaux (或等效)为表创建一个视图,其中一列作为字段名,另一列作为值
- typescript - apache-arrow 不能用打字稿编译
- sql - 数据库关系帮助(具有不同类型和组的用户)
- javascript - Ava+Sinon 联合测试。ReferenceError:未定义窗口