Shared variable across applications within the same AppPool?

前端 未结 1 508
情书的邮戳
情书的邮戳 2021-01-20 18:14

I\'m using Asp.net FW 4.6.

I have two applications under the same application pool that need to read (constantly) a predefined value which is object to

相关标签:
1条回答
  • 2021-01-20 18:41

    All ways of interprocess communication, such as Memory Mapped Files and Named Pipes can also be used for sharing data across applications within single AppPool, see for example Sharing memory between two applications.

    Because all apps in the same AppPool resides in the same process and are separated just by AppDomain boundaries, you have some additional options:

    • Use MarshalByRefObject to access object instance across AppDomain boundaries. There are already available wrappers that uses MarshalByRefObject to implement cross-AppDomain singleton, for example Stephen Cleary's CrossDomainSingleton or this one.
    • Use pointers and unsafe code to directly access memory allocated by Marshal.AllocHGlobal, especially if speed is your concern. But you will have to use one of the aforementioned methods to share memory address of allocated memory between applications.
    0 讨论(0)
提交回复
热议问题