Search code examples
.netvb.netdllshared-memoryshared

Is Shared variable in library shared their value across all application that referring that library?


This is possible duplicate. But, I couldn't able to find a prompt solution. Please help me out.

I have library project which has a class called GetData(ByVal contextId as Integer) function to get data from database and stores them into shared variable called Public Shared _ContextData As String. And, this library project referred by three window applications.

If all my three windows applications run simultaneously and try to get data with different contextId from database using the above method in that library.

Is there possible cause to share any one's contextId values across application?

I have referred below links already. But, they were telling the solution for web application.

Link 1

Link 2


Solution

  • Shared is only shared per application and not all applications, I'm afraid. When loading a DLL you load it into the application's memory, thus each application has its own instance of your library loaded into the application memory (which is why Shared doesn't work cross-application wise).

    If you want to share data across many applications you should look into Memory Mapped Files.