Daniel Camacho
Daniel Camacho

Reputation: 423

sharing variables between running applications in C#

I am developing in C# two simple applications, running in the same local machine without network requirements.

The first application initializes an DLL (Class1) and set a variable. The second application just read it the data which was previously stored. Both applications instanciates the same Class1.

Code:

My problem is that I do not know how to read a variable from another thread.

Application B must read the "variableName" set by application B

Thank you

Upvotes: 4

Views: 12708

Answers (4)

Ed Power
Ed Power

Reputation: 8531

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.

Upvotes: 1

Skizz
Skizz

Reputation: 71090

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..

Upvotes: 1

Christoph Fink
Christoph Fink

Reputation: 23113

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

Upvotes: 0

Oded
Oded

Reputation: 499152

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.

Upvotes: 4

Related Questions