Miscellaneous Concepts of .NET – Part 1
page 6 of 9
by Uday Denduluri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 42763/ 44

Creating Application Domains and Executing User code

The host can create application domains to run user code with security, isolation and unloading. It is not a better idea to run user code in the default domain. Let us list down the reasons for the same:

·         A default domain cannot be unloaded until the process exists

·         Security Isolation

Now that the host has created an application domain, we can execute user code in the domain. All code that is run in the CLR must be part of an assembly. An assembly is the deployment unit for types and resources and is the primary unit of execution in the CLR. The manner in which assemblies are loaded for execution depends largely on the host's specific scenario.

In general, there are two options:

·         The first option is to load precompiled assemblies from a disk.

·         The second option is to create assemblies on the fly using the API's in the System.Reflection.Emit namespace.

The code shown in Listing 2 is for creating an ApplicationDomain and executing an assembly into it. The code is written in C#. The Assembly that is loaded is an exe file.

Listing 2

ObjAppDomain = AppDomain.CreateDomain("My Application 1");
ObjAppDomain.ExecuteAssembly(@"C:\APPDOMAIN_Test.exe");

The code shown below is for unloading the Application domain from the memory.

Listing 3

AppDomain.Unload(ObjAppDomain);

View Entire Article

User Comments

Title: Good One   
Name: Shilpa Ginode
Date: 2008-05-06 2:52:19 AM
Comment:
Good article on Application Domain.
i learned this concept from this article.
Title: Good   
Name: pankaj
Date: 2007-07-18 8:00:21 AM
Comment:
good
Title: Thanks   
Name: Leonzhu
Date: 2007-05-07 10:31:56 AM
Comment:
Thanks for your excellant article
Title: Good Article on Application Doamin   
Name: Bhavannarayana.aluri
Date: 2007-04-30 1:11:05 AM
Comment:
Nice article on Application domain
Title: Excellant   
Name: Joydip
Date: 2007-04-26 3:17:22 AM
Comment:
This is an outstanding article Uday. Keep it up. I would like to see more articles of this kind from you.

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-16 4:43:35 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search