Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

What is an application domain – an explanation for .Net beginners

An application domain is the CLR equivalent of an operation system’s
process. An application domain is used to isolate applications from one
another. This is the same way an operating system process works. The
separation is required so that applications do not affect one another.
This separation is achieved by making sure than any given unique
virtual address space runs exactly one application and scopes the
resources for the process or application domain using that addess space.

However, a CLR application domain is seperate from a process. It is
contained within an operating system process. A single CLR operating
system process can contain multiple application domains. There are some
major pluses to having application domains within a single process.

  • Lower system cost – many application domains can be contained within a single sytem process.
  • The application in an application domain can be stopped
    without affecting the state of another application domain running in
    the same process.
  • A fault or exception in on application domain will not
    affect other application domains or crash the entire process that hosts
    the application domains.
  • Configuration information is part of an application domains scope, not the scope of the process.
  • Each application domain can have different security access levels assigned to them, all within a single process.
  • Code in one application domain cannot directly access code in another application domain. (* see below)

So you see, the CLR is like a mini-operating system. It runs a
single process that contains a bunch of sub-process, or application
domains.

* Direct communication cannot be acheived across application domains.
Application domains can still talk to eachother by passing objects via
marshalling by value (unbound objects), marshalling by reference
through a proxy (AppDomain-bound objects). There is a third type of
object called a context-bound object which can be marshalled by
reference across domains and also within the context of its own
application domain. Because of the verifiable type-safety of managed
code, the CLR can provide fault isolation between domains at a much
lower cost than an operating system process can. The static type
verification used for isolation does not require the same process
switches or hardware ring transitions that an operating system process
requires.

This entry was posted in .Net Development, Most Popular. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

28 Responses to What is an application domain – an explanation for .Net beginners

  1. keegan says:

    well posted

  2. siva kumar says:

    very nice article

  3. siva kumar says:

    very nice article for beginners who want to know the basics of the AppDomain concept in .NET.

    Keep going, waiting for these type of articles more.

  4. Arthur says:

    Very nice.

  5. efactor says:

    Raymond, It’s the coolest blog and we love it.
    Keep posting such short, concise and up to the point blogs. It helps a lot.

  6. chnati says:

    nice ..thank u

  7. shrikant sherekar says:

    I am so thankful man, its conceptually really helpful for anybody who wants to starts studying .NET or who is expert in .NET.

    Thanks Sir!!!

  8. Jeff R says:

    Great intro…..I am looking into using application domains for our main application that will allow end users to create their own plug ins to handle custom processing logic. Seems like launching the plugins in their own domain might be a good idea so the main application doesn’t come to a flaming halt.

  9. Abhishek Saxena says:

    Really a very good blog…… keep posting such blog….. will help so many developers……. Greate going…….. :)

  10. Nagaraj says:

    It is a very good starter for a developer who has’nt worked on Application Domains. I hope to look forward for an simple example in the future so that it would be much more helpful in real world scenario.

    Thanks for the post and keep posting these for beginners.

  11. Abey says:

    i have a doubt on AddDomains.. suppose i have a website on the server. If 10 users access that website simultaneuosly, will 10 AppDomains get created, or its like there is only one AppDomain for that site, and there will be multiple threads (from every user), accessing the appDomain?

  12. Najeeb says:

    Hi friend… Its a wonderful artle.. It really helped me a lot. Thanks..

  13. kate says:

    more information should be there..dude this is known by all..

  14. Robert Sharp says:

    I’ve actually got a problem with child AppDomains causing the hosting process to crash. All code in the hosted AppDomains that I have is contained in a giant Try…Catch block to avoid this, and for the most part it works beautifully. But there’s one particular Service (that’s what we call the children of the Host) that Interops with Outlook (Ok, I haven’t seen the code that does it, I’m just assuming it uses Interop), and if Outlook happens to run into trouble (in the middle of the night when the Exchange server is down), it crashes the Host, so we lose all our Services along with it. Luckily I added session saving to the Host, to keep track of what was loaded in the event of a crash or power outage, but it’s still annoying that the “uncrashable” crashes. Any tips? I mean, I do need to get a look at the code that uses Outlook… it was made by a slightly amature programmer, after all… I just would have thought the AppDomain structure would prevent it from being a problem.

  15. Vishak says:

    This tutorial about the Application Domain is very useful. Got an idea about it, after reading this article I guss any onw can dig into it.

  16. Naresh Thandu says:

    very good

  17. Ruju says:

    Good one!!! I was not aware of adv. of app. domain. Thanx

  18. prashant says:

    Nice

    thank you.

  19. Nickel says:

    Very useful

  20. Saurabh Shah says:

    Very much helful tutorial

  21. darshan says:

    I hav que …..when ll application crashs n ll it affect other application .what may be the reason behind it?

  22. Sandeep says:

    when does a appDomain Crash? I have a case where i create a number of appDomains and have to capture when any appDomain crash..

  23. rlewallen says:

    Sahil, thanks. I’m glad there are people out there who enjoy them. I pretty much leave the code and samples stuff up to David, he’s so good at it 😉

    John and Geoff, I’ll do an intermediate level post on AppDomains with some elaborations on where you might want to use them and communicating across them. John, I’ve never created an AppDomain either for my own purposes. You really only want to create one in order to get the isolation and security boundries needed for executing some untrusted managed code. Jeffery Palermo has a post talking about how he runs a trace listener in a appdomain to contain memory usage and state here: http://dotnetjunkies.com/WebLog/jpalermo/archive/2005/02/22/56163.aspx

    Geoff, to dig in deeper while I put up another post, you might want to check out the System.MarshalByRefObject and its derivatives. You also might want to check out remoting, which is all about communicating across app domains.

    Also, for those of you seeking more information on creating your own application domains, check out the System.AppDomain class, which is derived from System.MarshalByRefObject.

    My local .Net Developers meeting is this evening, so I probably can’t get the next post done for another day or so, sorry.

  24. Hey, don’t apologise. Just do better next time!!! *grin* Just kidding :)

  25. Dude, cool. I’ve been meaning to research into appdomains for a very long time now, and just never got around to it. One question: Given that calls from one appdomain to another are marshalled, what’s the cost involved in the calls?

    Now that you’ve done a beginner post (of which the contents, while well written and very appreciated :) move on to the intermediate and advanced levels where my geekiness will thrive *grin* Seriously, the only thing that’s stopped me playing is my lack of desire to take the time yet to find some examples. If you could do that, it’s be sweet.

  26. Sahil Malik says:

    Man I love your blog. Seriously, the love and effort you put in your posts to really write meaningful posts useful to both a beginner and an expert makes it an utmost heartfelt pleasure to read them.

  27. johnpapa says:

    Raymond,

    I’ve never had cause to use App Domains (mostly through ignorance I assume). I understand how they work but when I try to find a place to put it to practical use, well, I can’t think of a practical one. I am sure there are some that I just haven’t run across or thought of. Can you elaborate?

Leave a Reply