How to create a C # library loaded into memory only once?

I would like to create a class library DLL in C # that will have a Static Class. This static class has 1 private static member (int) with a public static property for it.

I want that for every C # application that references this DLL, it will get the same static class.

Value If application 1 changes the value of the static member to 5, and then Application2 tries to get the value of the property, it will get: 5.

Despite the fact that these are two different applications (EXE).

In simple words, I want this entire class library to be β€œstatic”, so it will only be loaded from it into memory only once, and then its one value will be transferred to other EXEs that reference it.

thanks

+6
c # class
source share
3 answers

An attractive solution for shared data among all processes on one computer is shared memory. You will need to rewrite your properties in order to get a common value, and the class will be loaded several times in each process that uses your library, but it will behave as if you did it correctly.

Here is a StackOverflow question that will get you started:

  • How to implement shared memory in .NET?

It refers to a complete shared memory library that you can use.

+3
source share

What you are looking for is some form of IPC or RPC . One option: .NET Remoting .

+2
source share

I am Omer, I signed up, so it looks like I'm a different user.

Regarding what Damien_The_Unbeliever said, let me describe what I usually want to do, so you can direct me to a better solution for this case.

I created a nice application. This application has a graphical interface. I want to add another way to manage this application, which will be associated with providing an API for it - methods and properties that other applications can use to manage my application.

And I plan to do the following: Create a DLL with a static class, put the core of my application in this class, and then the GUI and, possibly, all other applications, use this class.

note that this class will contain not only data that can be saved, but also links to "live" objects (i.e. open collaboration ports, etc., etc.), therefore storage on disk, and reading from it would not be a good solution here. I need this 1 static class to be accessible from all the applications that they want, and that they all get the same static class.

So, I need this class to be static, and I need the library to be β€œstatic”. (There is no such thing in .NET as a "static library", I know. Please note that I am not talking about a static library, as in C ++, there is something else. I am talking about a DLL that creates only one times, for all applications that use it).

0
source share

All Articles