I would like to create a Class Library DLL in C#, that will have a Static Class in it. That static class has 1 private static member(int), with a public static property for it.
What I want is, that for Every C# Application that references this DLL, it will get the same static class.
Meaning If Application1 changes the static member's value to be 5, and then Application2 tries to get the value of the propery, it will get: 5.
Despite the fact that those are two开发者_JAVA技巧 different applications(EXEs).
In simply words, I want this whole class library to be "static", so only once will be loaded of it to memory, and then its single value will be shared accross different EXEs that reference it.
Thank you
An attractive solution to shared data amongst all processes on the same computer is shared memory. You will have to rewrite your properties to retrieve the shared value, and the class will be loaded multiple times into each process that uses your library, but it will behave as though there were only one copy, if you do it correctly.
Here is a StackOverflow question to help you get started:
- How to implement shared memory in .NET ?
It links to a complete shared-memory library you can use.
What you're looking for is some form of IPC or RPC. One option is .NET Remoting.
I am Omer, I registered so it looks as if I am a different user.
Regarding what Damien_The_Unbeliever said, allow me all to describe what I generally want to do, so you can direct me towards the best solution for that case.
I have created a nice application. This application has a GUI. I want to add another way to operate this application, which will be via exposing an API for it - methods and properties that other applications can use, to operate my application.
And what I plan to do is: Create a DLL with a static class, put the core of my application in that class, and then have the GUI, and potentially all other applications, use that class.
please note that this class will hold not only data that can be stored, but also references to "live" objects(i.e. open coomunication ports, etc etc), so storing to disk, and reading from it will not be a good solution here. I need this 1 static class, to be accessible from all applications that want, and that all of them will get the same static class.
So, I need this class to be static, and I need the library to be "static". (no such thing in .NET as "static library", I know. please note that I am not talking about static library like in C++ - there it's something else.. I am talking about a DLL that is created once only, for all applications who use it).
精彩评论