Usage of AppDomain in C#

前端 未结 5 1246
耶瑟儿~
耶瑟儿~ 2020-11-27 10:46

What is the most important use of AppDomains in C#?

5条回答
  •  爱一瞬间的悲伤
    2020-11-27 11:30

    I can't tell you what the most important use is, since that depends on the situation.

    AppDomains are useful for sandboxing parts of your application. You can load extensions in an AppDomain and unload them again - something you cannot otherwise do. You can assign specific rights to AppDomains. Per default objects in different AppDomains cannot access each other.

    AppDomains can be viewed as lightweight processes as they give you many of the same features. However, unlike a Process new AppDomains do not have their own thread per default. You have to manage AppDomains and threads yourself.

    Also, AppDomains all share the same managed heap. This is usually not a problem, but it may have surprising effects as some instances like strings are shared among AppDomains. For regular use this is not an issue, but if you use strings for locking, threads in different AppDomain can affect each other.

提交回复
热议问题