VisualBuilder
  Home > Dotnet > Tutorials > Application Domain in .Net - .NET Tutorial
Tell a friend
Link to us
Total Members
      Members: 84606
     
Sitemap Forum Chat
Home
.NET Tutorial Home
1 . Overview of .Net Framework
2 . .Net Components:
3 . CLR (Common Language Runtime)
4 . Steps to Run a program in CLR
5 . Assembly
6 . GAC (Global Assembly CACHE)
7 . Strong Name in .Net Assembly
8 . ILDASM: Intermediate Language Disassembler in .Net
9 . Custom Attributes in .Net
10 . Application Domain in .Net
11 . Code Access Security in .Net
12 . Type System in .Net -1
13 . Type System in .Net -2
14 . Reflection: Inspection of a Type\'s Metadata
15 . Introduction to Generics
16 . Generic Classes and Methods
17 . Generic Methods in .Net 2.0
18 . Overview of Inheritance in Generics classes
19 . Connection pooling in .Net Applications
20 . Deployment in .Net
 
Dotnet Group Home
Dotnet Discussion (9)
Dotnet Members (2825)
Dotnet Resources
Dotnet Source Code (0)
Dotnet Articles (0)
Dotnet Blogs
Dotnet Jobs
Dotnet Components (2)
Dotnet Books
Dotnet Websites (43)
Dotnet News (186)
Dotnet Q & A (3)
- Dotnet Ask Question
- Dotnet Questions
- Dotnet Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (432 )
Source Code (3217 )
Articles (11 )
Components (1589 )
News (880 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Dotnet Tutorial
 Application Domain in .Net
  << Prev: Custom Attributes in .Net Next: Code Access Security in .Net >>

The application Domain is used to isolate an application from other applications. One process has its own virtual memory and does not over lap the other process's virtual memory; due to this one process can not crash the other process. As a result any problem or error in one process does not affect the other process. In .Net they went one step ahead introducing application domains. In application domain multiple applications can run in same process with out influencing each other. If one of the application domains throws error it does not affect the other application domains.


 


Win32 processes provide isolation by having distinct memory address spaces. This is effective, but it is expensive and doesn't scale well. The .NET runtime enforces AppDomain isolation by keeping control over the use of memory - all memory in the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each other's memory. Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, or by using a proxy to exchange messages.
   


MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value.   When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.


 


With the .NET architecture we have a new boundary for applications: application domains . With managed IL code the runtime can ensure that access to the memory of another application inside a single process can't happen. Multiple applications can run in a single process within multiple application domains.


 





 


 


Creating Application Domain


 


The AppDomain class is used to create and terminate application domains, load and unload assemblies and types, and to enumerate assemblies and threads in a domain. AppDomains are usually created by hosts. Examples of hosts are the Windows Shell, ASP.NET and IE. When you run a .NET application from the command-line, the host is the Shell. The Shell creates a new AppDomain for every application. AppDomains can also be explicitly created by .NET applications.  


 


Example: Demonstrate Application Domain


 


Create a C# Console Application i.e. “FirstApplication”


 


using System;


using System.Collections.Generic;


using System.Text;


using System.Runtime.Remoting;


 


namespace ConsoleApplication1


{


class Program1


{


public Program1() {


Console .WriteLine( "Constructor in First Application" );


}


static void Main ( string [] args)


{


Console .WriteLine( " Main in domain {0} called" , AppDomain .CurrentDomain.FriendlyName);


display();


}


static void display() {


Console .WriteLine( "Display Calls" );


}


}


}


 


Here we are creating one application that have constructor and on method. We here display the value of the current application domain that this application belongs too.


 


 


Output:


 


G:\cSharp-Examples\ConsolesApplications\FirstApplication\FirstApplication\bin\ Debug >FirstApplication.exe


Main in domain FirstApplication.exe called Display Calls


 


 


Note:-The second project created is again a C# Console Application: “SecondApplication”. First, display the name of the current domain using the property FriendlyName of the AppDomain class. With the CreateDomain() method, a new application domain with the friendly name New AppDomain is created. Then load the assembly “FirstApplication” into the new domain and call the Main () method by calling ExecuteAssembly ():


.


using System;


using System.Collections.Generic;


using System.Text;


 


namespace ConsoleApplication2


{


class Program2


{


static void Main ( string [] args)


{


AppDomain currentDomain = AppDomain .CurrentDomain;


Console .WriteLine(currentDomain.FriendlyName);


AppDomain secondDomain = AppDomain .CreateDomain( "New AppDomain" );


secondDomain.ExecuteAssembly( "FirstApplication.exe" );


}


}


}


 


Note:- Befor running this application exe, place the “FirstApplication.exe” inside the bin folder under this application directory


 


Output:


 


G:\cSharp-Examples\ConsolesApplications\SecondApplication\SecondApplication\bin\Debug>SecondApplication.exe


SecondApplication.exe


Main in domain New AppDomain called Display Calls


 




  << Prev: Custom Attributes in .Net Next: Code Access Security in .Net >>
Dotnet Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
Skype vs. sipcall
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising