Is static context always single in C#?

前端 未结 3 524
星月不相逢
星月不相逢 2020-12-24 10:53

I have a library that has a static field inside. I want to create an app and reference this library so I\'d have two instances of this static field. .Net runtime does not al

3条回答
  •  被撕碎了的回忆
    2020-12-24 11:18

    That's not as crazy as you think. In fact, you can achieve this using AppDomains.

    Each AppDomain has its own storage location for static variables. So you can just create a second AppDomain in your process, and communicate between them using an object that inherits from MarshalByRefObject like in this MSDN example.

提交回复
热议问题