不同进程之间共享dll数据
我必须用 C# 实现一个 dll,其中包含任务列表。该 dll 的职责是管理这些任务。不同的进程将与该 dll 进行交互,每个进程都有自己的任务,由任务 ID 标识。
但由于每个进程都有自己的 dll 数据副本,因此面临的挑战是如何管理这个列表。该列表必须由所有实例共享。我在 google 上搜索共享 dll 数据并发现这个-
data_seg 方法似乎仅适用于静态数据,没有动态添加/删除列表中任务的范围。 (如果我错了请纠正我)。
我应该使用内存映射文件吗?如果我只使用基本文件 I/O 怎么办?我正在考虑将这个任务列表序列化到一个文件中。然后,每个进程都可以通过设置 FileShare.None 打开它。这样,文件访问将是互斥的,如果文件已打开,进程将等待。
请让我知道哪种方法更好或有其他更好的选择。
谢谢
I have to implement a dll in C# which contains a list of tasks. The responsibility of this dll is to manage these tasks. Different processes will interact with this dll, each for its own task, identified by the task ID.
But since each process will have its own copy of the dll data, the challange is how to manage this list. This list has to be shared by all instances. I googled for sharing dll data and came across this-
data_seg approach seems useful only for static data with no scope for dynamically adding/deleting tasks in the list. (Correct me if I am wrong).
Should I go for memory mapped files? What if I just use basic file I/O? I am thinking of serializing this list of tasks into a file. Each process can then open it with FileShare.None set. That way the file access will be mutually exclusive and a process will wait if the file is already opened.
Please let me know which is the better approach or any other better alternatives.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过将 dll 托管在 WCF 服务中?然后,您可以让您的应用程序向此服务发出客户端调用。数据可以保留在托管 wcf 进程中。
Have you thought about hosting the dll in a WCF service? You could then have your apps make client calls to this service. The data could persist in the hosting wcf process.