Raymond Lewallen

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.


Posted Sun, Apr 3 2005 8:48 PM by Raymond Lewallen

[Advertisement]

Comments

John Papa wrote re: What is an application domain - an explanation for .Net beginners
on Sun, Apr 3 2005 9:35 PM
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?
Sahil Malik wrote re: What is an application domain - an explanation for .Net beginners
on Sun, Apr 3 2005 11:24 PM
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.
Geoff Appleby wrote re: What is an application domain - an explanation for .Net beginners
on Mon, Apr 4 2005 3:52 AM
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.
Geoff Appleby wrote re: What is an application domain - an explanation for .Net beginners
on Mon, Apr 4 2005 6:20 AM
Hey, don't apologise. Just do better next time!!! *grin* Just kidding :)
Raymond Lewallen wrote re: What is an application domain - an explanation for .Net beginners
on Mon, Apr 4 2005 6:24 AM
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.
Patrick Steele's .NET Blog wrote Most recently subscribed to.
on Wed, Apr 6 2005 8:00 PM
Sandeep wrote re: What is an application domain - an explanation for .Net beginners
on Tue, Aug 8 2006 8:51 AM
when does a appDomain Crash? I have a case where i create a number of appDomains and have to capture when any appDomain crash..
darshan wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Sep 14 2006 12:46 AM

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

TrackBack wrote http://en.wikipedia.org/wiki/clr_application_domain
on Tue, Mar 27 2007 9:13 PM
Saurabh Shah wrote re: What is an application domain - an explanation for .Net beginners
on Sat, May 26 2007 5:32 AM

Very much helful tutorial

Nickel wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Aug 9 2007 5:10 AM

Very useful

prashant wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Nov 1 2007 2:11 AM

Nice

thank you.

Ruju wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Dec 6 2007 2:22 AM

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

Naresh Thandu wrote re: What is an application domain - an explanation for .Net beginners
on Mon, Feb 4 2008 9:02 AM
very good
Vishak wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Apr 17 2008 1:04 AM

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.

Robert Sharp wrote re: What is an application domain - an explanation for .Net beginners
on Fri, Apr 18 2008 1:08 PM

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.

kate wrote re: What is an application domain - an explanation for .Net beginners
on Wed, Apr 30 2008 5:58 AM

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

Patent management » Application. Generally a, Application Domain wrote Patent management » Application. Generally a, Application Domain
on Thu, May 8 2008 1:13 PM

Pingback from  Patent management » Application. Generally a, Application Domain

Najeeb wrote re: What is an application domain - an explanation for .Net beginners
on Wed, Jun 18 2008 5:37 AM

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

Abey wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Jul 24 2008 8:10 AM

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?

Nagaraj wrote re: What is an application domain - an explanation for .Net beginners
on Sun, Sep 7 2008 2:21 AM

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.

IWebThereforeIAm wrote My first StackOverflow question
on Sat, Sep 20 2008 2:34 PM

I've been asked a few times about appdomains. I know the basics in a theoretical way, but I was unclear on the actual application. I asked my first question at StackOverflow, Good example of use of AppDomain, to clarify. 2008-09-20:...

Abhishek Saxena wrote re: What is an application domain - an explanation for .Net beginners
on Fri, Oct 3 2008 7:20 AM

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

Jeff R wrote re: What is an application domain - an explanation for .Net beginners
on Tue, Oct 7 2008 3:50 PM

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.

shrikant sherekar wrote re: What is an application domain - an explanation for .Net beginners
on Wed, Dec 10 2008 3:22 PM

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!!!

Atteint de JavaScriptite Aiguë [Cyril Durand] wrote Créer son serveur ASP.net : du socket au HttpRuntime, la Page en ligne de mire
on Sat, Jan 24 2009 1:16 PM

Par curiosité, j'ai eu envie d'héberger manuellement ASP.net, c’est à dire coder l’application hôte,

chnati wrote re: What is an application domain - an explanation for .Net beginners
on Sun, Feb 22 2009 11:08 AM

nice ..thank u

efactor wrote re: What is an application domain - an explanation for .Net beginners
on Mon, Mar 9 2009 2:21 AM

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.

Arthur wrote re: What is an application domain - an explanation for .Net beginners
on Thu, Sep 10 2009 10:08 PM

Very nice.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?