[ACCEPTED]-What is a .NET application domain?-appdomain

Accepted answer
Score: 84

An AppDomain basically provides an isolated region 19 in which code runs inside of a process.

An 18 easy way to think of it is almost like a 17 lighter-weight process sitting inside of 16 your main process. Each AppDomain exists 15 within a process in complete isolation, which 14 allows you to run code safely (it can be 13 unloaded without tearing down the whole 12 process if needed), with separate security, etc.

As 11 to your specifics - if you run code in 2 10 different AppDomains within a process, the 9 code will run in isolation. Any communication 8 between the AppDomains will get either serialized 7 or handled via MarshallByRefObject. It 6 behaves very much like using remoting in 5 this regard. This provides a huge amount 4 of security - you can run code that you 3 don't trust, and if it does something wrong, it 2 will not affect you.

There are many more 1 details in MSDN's description of Application Domains.

Score: 22

It is an isolation layer provided by the 4 .NET runtime. As such, App domains live 3 with in a process (1 process can have many 2 app domains) and have their own virtual 1 address space.

App domains are useful because:

  • They are less expensive than full processes
  • They are multithreaded
  • You can stop one without killing everything in the process
  • Segregation of resources/config/etc
  • Each app domain runs on its own security level
Score: 1

If you look at it from processor internal 24 details perspective it sets different value 23 for Code Segment (the CS) register. code 22 and CS:IP (Instruction Pointer) register 21 is the one that is in execution by the processor.

(I've 20 chosen to skim page table related discussion 19 for brevity).

AppDomain marks this boundary. for 18 code safety.

The reason for giving this background 17 is to get away with question of these sort: 1. how 16 can we access resource across two app domain 15 (yes using pipes or some other sharing mechanis 14 not directly as CS:IP cant be set to some 13 other appdomain. It is just the OS that 12 can do it. Not the CLR)

  1. Could there be multiple 11 threads in app domain. Technically yes as 10 the CS value going to be in the current 9 process. you can change IP to something 8 else by a jump statement (function call/goto 7 combination)

  2. can two threads in two different 6 app domain communicate (No. refer point 5 1.)

  3. can two threads in single app domain 4 communicate (Yes. refer point 2)

several 3 other combination of these cases could be 2 answered by little knowledge of how CS:IP 1 works.

Score: 0

Each application running within a process, AppDomain 18 is also a light-weight process or we can 17 say logical unit which having group of assemblies 16 (this is a container which contain group 15 of assemblies ) and this exist inside of 14 the process at isolation level of same process, this 13 allows to run multiple assemblies within 12 same process and prevent them for direct 11 access.

Running Dot Net Application Within AppDomain: Once any dot net application run, Operation 10 system shell load CLR into a process and 9 new AppDomain been created in the same process 8 and load all the assemblies in the created 7 AppDomain, now from the AppDomain code 6 will get executed.

When to Custom AppDomain: We can create own AppDomain, now 5 the thing is in which scenario we can create 4 own AppDomain. Suppose run time we need 3 to add or remove the assemblies without 2 interruption the running application then 1 we can create own AppDomain.

More Related questions