What are app domains used for?

后端 未结 5 1545
傲寒
傲寒 2020-12-15 20:49

I understand roughly what an AppDomain is, however I don\'t fully understand the uses for an AppDomain.

I\'m involved in a large server based C# / C++ application an

5条回答
  •  被撕碎了的回忆
    2020-12-15 21:42

    Actually, it is not true that a critical fail in one AppDomain can't impact others. In the case of bad things, the best bet it to tear down the process. There are a few examples, but to be honest I haven't memorised them - I simply took a mental note "bad things = tear down process (check)"

    Benefits of AppDomain:

    • you can unload an AppDomain; I use this for a system that compiles itself (meta-programming) based on data from the database - it can spin up an appdomain to host the new dll for a while, and then swap it safely when new data is available (and built)
    • comms between AppDomains are relatively cheap. IMO this is the only time I am happy to use remoting (although you still need to be really careful about the objects on the boundary to avoid bleeding references between them, causing "fusion" to load extra dlls into the primary AppDomain, causing a leak) - it is really easy too - just CreateInstanceAndUnwrap (or is it CreateInstanceFromAndUnwrap?).
    • vs spawing an extra process - you could go either way; but you don't need another exe for AppDomain work, and it is much easier to set up any comms that you need

提交回复
热议问题