Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

.net - Good example of use of AppDomain

I keep getting asked about AppDomains in interviews, and I know the basics:

  • they are an isolation level within an application (making them different from applications)
  • they can have threads (making them different from threads)
  • exceptions in one appdomain do not affect another
  • appdomains cannot access each other's memory
  • each appdomain can have different security

I still don't get what makes them necessary. I'm looking for a reasonable concrete circumstance when you would use one.

Answers:

  • Untrusted code
  • Core application protected
    Untrusted/3rd party plugins are barred from corrupting shared memory and non-authorized access to registry or hard drive by isolation in separate appdomain with security restrictions, protecting the application or server. e.g. ASP.NET and SQL Server hosting component code
Trusted code
  • Stability
    Application segmented into safe, independent features/functionality
  • Architectural flexibility
    Freedom to run multiple applications within a single CLR instance or each program in its own.

Anything else?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Probably the most common one is to load assemblies that contain plug-in code from untrusted parties. The code runs in its own AppDomain, isolating the application.

Also, it's not possible to unload a particular assembly, but you can unload AppDomains.

For the full rundown, Chris Brumme had a massive blog entry on this:

http://blogs.msdn.com/cbrumme/archive/2003/06/01/51466.aspx

https://devblogs.microsoft.com/cbrumme/appdomains-application-domains/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...