sharing variables between running applications in C#

核能气质少年 提交于 2019-11-28 11:35:53

You need some sort of mechanism to communicate between the applications.

This can be through the registry, files, memory mapped files etc...

If both applications are expected to do write, you need to add synchronization logic to your code.

Skizz

There is no simple way for Application B to read data created in Application A. Each application has its own address space and thus do not know of the others existence.

But, there are ways to do this!

See this question for one method..

I've successfully used two methods:

  1. Use a database table to contain your common data. If you wrap your calls to it in transactions then you also protection from concurrency issues.

  2. Use PersistentDictionary to store your data, protected by a mutex. You must have some interprocess locking since PersistentDictionary can only be open by one process at a time.

You can use .net Remoting to communicate between your two application.
Remoting also does not require a network address to communicate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!