Application Domains in .NET
page 6 of 13
by Joydip Kanjilal
Feedback
Average Rating: 
Views (Total / Last 10 Days): 53524/ 161

Creating an Application Domain

The AppDomain class abstracts application domains.  An Application domain can be created using AppDomain class of System namespace, but in most cases they are created and managed by the runtime hosts that execute the application's code.  An Application Domain is created using one of the following overloaded CreateDomain methods of the System.AppDomain class.

Listing 1

public static AppDomain CreateDomain(String appDomainName)
public static AppDomain CreateDomain(String appDomainName, Evidence securityInformation)
public static AppDomain CreateDomain(String appDomainName, 
   Evidence securityInformation, AppDomainSetup appDomainSetupInformation)
public static AppDomain CreateDomain(String name, 
   Evidence securityInformation, String appBasePath, String appRelativeSearchPath,
   bool shadowCopyFiles)

All these overloaded methods are static in nature and can be invoked without instantiating the class.  The first overloaded method accepts the name of the Application Domain to be created and creates an Application Domain.  However, the second accepts two parameters; the first one being the name of the Application Domain to be created while the second is a reference of the System.Security.Policy.Evidence for specifying the security policy for the application.  The third overload accepts an additional parameter, a reference of System.AppDomainSetup, which is used to configure how the assemblies would be loaded into the application.  The Evidence parameter refers to a collection of the security information on the application domain.  The last overloaded CreateDomain method accepts some additional parameters without defining a System.AppDomainSetup object reference.  The return value of each of these overloaded methods is an AppDomain object that represents the newly created application domain.


View Entire Article

User Comments

Title: Answer to reader's queries   
Name: Joydip Kanjilal
Date: 2006-11-15 3:44:34 PM
Comment:
Dear All,

Thanks a lot for the comments. Please note that an Application Domain belongs to only a single process, but a single process can hold multiple Application Domains. This is what I wanted to highlight in this article. Please let me know by e-mail or otherwise, if you still have any confusions.

Regards,

Joydip.
Title: it is nice   
Name: gir
Date: 2006-11-06 7:59:31 AM
Comment:
everything is cool!
Title: Rewrite please   
Name: Juan Romero
Date: 2006-10-25 5:50:22 PM
Comment:
This is a great article but some things seem contradictory. For example "A process runs exactly one application and has its own virtual address space, executable code and data." and "Multiple applications can execute within a single process by loading them into separate application domains.".
Hopefully the author rewrites this article. It is an interesting topic.
Title: Examples would be helpful   
Name: Reader
Date: 2006-10-13 9:11:12 PM
Comment:
It would be nice to read about some examples of why I would want to use application domains. Not necessarily code to do it, but real world reasons to use them and how the system would benefit vs. not using app domains.
Title: suggestion   
Name: reader
Date: 2006-10-13 5:17:38 PM
Comment:
Every application has a process space in which it is executed. This provides isolation between processes that ensures that code in one process does not have direct access to the code in another process. An application domain is lighter than a process and therefore, it is referred to as a light weight process. Application domains are appropriate for scenarios that require isolation without the heavy cost associated with running an application within a process. In other words, an Application domain provides a secure and versatile unit of processing that the common language runtime can use to provide isolation between applications running in the managed environment of Microsoft .NET. It should be noted here that applications that run on different Application Domains can only share information by using Microsoft .NET's Remoting technology. A process is the running instance of a program and is characterized by a change of state and attributes and identified by having a Process Control Block of its own. A process runs exactly one application and has its own virtual address space, executable code and data. Like an Application Domain, a process is not permitted to access the code or data of another process. The exact behavior of a particular process is based on the operating system on which it executes. Multiple applications can execute within a single process by loading them into separate application domains.


I don't the difference between the process and app domain in the above paragraph. should be rewritten.
Title: Thread Pools in AppDomains   
Name: David Martin
Date: 2006-10-13 5:14:40 AM
Comment:
Good article. Clearly explained. It was very helpful for some of junior developers on my team.
You discuss thread relationships at the end as a one to one relationship between application domain and thread. I think this is slightly mis-laeding. The thread is abstracted from the app domain, described as a soft thread - with the true process thread described as a hard thread. The relationship between a hard thread and a soft thread is one per AppDomain, every time a hard thread enters an AppDomain it is always associated with the same soft thread of execution (unless it has changed in framework 2.0). The hard thread TLS contains data references to soft threads in different AppDomains within the same process. The CLR abstraction provides us a soft thread TLS.
So if there are 3 AppDomains each using 3 threads which would represnet 9 soft threads the process and OS may only be consuming 3 Hard (OS) threads.

I hope this is of help to someone. I have a presentation explaining this which I will upload somewhere - in the mean time if anyone wants it drop me a line at mrdavemartin@hotmail.co.uk
Title: Good   
Name: kesavan
Date: 2006-10-09 7:14:42 AM
Comment:
Nice Article
Title: App serialization and restart?   
Name: C
Date: 2006-08-31 12:09:01 PM
Comment:
Can you cover how to start an application in an application domain, pause it, save it to disk, load it back into an application domain and then restart the application from its paused state?
Title: good   
Name: sara
Date: 2006-08-31 9:27:17 AM
Comment:
very good article. many thanks to the author
Title: EXCELENT   
Name: Mahesh
Date: 2006-08-22 2:24:48 AM
Comment:
GOOD ONE
Title: acknowledgement   
Name: Sagar Debnath
Date: 2006-08-17 6:57:02 AM
Comment:
Gud article about appdomain in .net.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-07 7:26:27 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search