简体   繁体   English

在 C# 中的两个独立 Windows 应用程序之间共享数据

[英]Sharing data between two independent Windows applications in C#

I have two applications that use my clients database(s), but have no mutual dependency.我有两个应用程序使用我的客户端数据库,但没有相互依赖。 The problem is that I need to make an application for configuration in which the administrator could set the parameters.问题是我需要制作一个应用程序进行配置,管理员可以在其中设置参数。 For instance which database to which the two applications connect and some other parameters, mostly string and numerical.例如两个应用程序连接到哪个数据库以及其他一些参数,主要是字符串和数字。 These parameters must affect both applications.这些参数必须影响这两个应用程序。

The first solution that I thought of is to make a configuration file in which I could store the data and the applications would read that file on startup.我想到的第一个解决方案是制作一个配置文件,我可以在其中存储数据,应用程序将在启动时读取该文件。 The problem with this approach is that it is not very safe (even if I encrypt the data in the file).这种方法的问题在于它不是很安全(即使我加密了文件中的数据)。

Is there a way to send data from one application to the other, assuming that each application is created as an individual project?假设每个应用程序都是作为一个单独的项目创建的,有没有办法将数据从一个应用程序发送到另一个应用程序?

You can use Memory-Mapped Files您可以使用内存映射文件

You can use it as a file, and access from different executables.您可以将其用作文件,并从不同的可执行文件进行访问。

Build your own class for interfacing with it.构建您自己的类以与之交互。

Tutorials:教程:

Programming Memory-Mapped Files with the .NET Framework 使用 .NET Framework 编程内存映射文件

Working with memory mapped files in .NET 4 在 .NET 4 中使用内存映射文件

or you can even use named pipe : http://www.eggheadcafe.com/articles/20060404.asp Or make communication with socket.或者你甚至可以使用命名管道: http : //www.eggheadcafe.com/articles/20060404.asp或者使用套接字进行通信。

You have a plenty of solution.你有很多解决方案。 If you need more details, feel free to ask.如果您需要更多详细信息,请随时询问。

Best regards, Sylvain.最好的问候,西尔万。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM