Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我读到.Net中静态字段的粒度单位是每个AppDomain,而不是每个进程。是否可以创建一个进程范围的单例对象?
您必须使用编组调用跨 AppDomain 传递信息。因此,您需要在父 AppDomain 中创建状态对象,然后将其传递给任何想要使用它的子对象。如果您不必这样做,那么您将在 AppDomains 之间共享内存,这违背了目的。
在每个 AppDomain 中,您可以有一个单例,其中包含对主域中实际单例的(编组)引用的引用。所以你的代码看起来仍然是“singleton-y”,但它背后会有一些隐藏的布线。