2

I have a class that will be holding information: Id, Name, etc. This is part of a class library written in C#.

2 app's both have project references to the library(DLL).

Both apps are standlone executables.

App1 will initially set the information (Id, Name, etc.)

I want App2 to be able to access the values that were set App1.

I have tried making the library class static and non static but am still unable to get App2 to "see" the values set by App1. I realize I could serialize the data and am trying to avoid doing if possible.

user2864740
  • 60,010
  • 15
  • 145
  • 220
cs6505
  • 23
  • 3
  • How long is "share" and "persist"? What happens to the information when the processes end? What happens if one (either) process is terminated and then restarted? Are there any restrictions on device (e.g. temporary or permanent file) usage? – user2864740 Jun 04 '14 at 20:56
  • If the apps run as separate processes, making the class static won't help. You'll need to use some kind of inter-process communication to share the data, whether that's a memory-mapped file, DB, WCF service, or something else. – pmcoltrane Jun 04 '14 at 20:58
  • It doesn't work like that. Just because both apps reference the same library, they do not share it. The library is loaded and executed in the domain of that app. You need a persistent store. Database, file, or send data from one app to another. – Roman Mik Jun 04 '14 at 20:58

4 Answers4

0

If they are shared DLLs then you cannot reach out the value that is being set by App1. Because shared DLLs managed differently by each application. You cannot jump out and get a value from other app's DLL file directly.

Also check this answer: IPC in C#, sending text from one exe to another exe

Community
  • 1
  • 1
Bura Chuhadar
  • 3,653
  • 1
  • 14
  • 17
0

An executable is an isolated entity. When you run it has it's own process and memory space. You cannot access memory of a different process.

If you want to use a value saved in process A by some other process B, you either have to connect these 2 processes using some real time connection technology (e.g. host a WCF service on one executable and make calls from another executable) or have some intermediate object (e.g. save serialized object to a file and open that in different process).

dotnetom
  • 24,551
  • 9
  • 51
  • 54
0

You can't access the "same" fields/properties of a shared DLL, not even if the classes are made static because... well, lot's of reasons. Apps might reference the same DLL but they still have own instances of the classes.

Maybe easiest would be to persist the information temporarily (XML, format of your own making , ...) or serialize the instance holding your data and then deserializing it on the other app.

If you are still not convinced, then I'd point you to this Microsoft sample (VB.NET) about sending and receiving messages between different Windows applications

http://support.microsoft.com/kb/176058

I have used this approach myself and it works quite nice for simple cases.

Happy coding.

Mikko Viitala
  • 8,344
  • 4
  • 37
  • 62
-1

Two different application so its two different process (not thread!) The easyest if you use WCF or Remoting, like: http://www.codeguru.com/csharp/csharp/cs_syntax/remoting/article.php/c9251/NET-Remoting-Using-a-New-IPC-Channel.htm

becike
  • 195
  • 1
  • 8