Welcome to weblogs.com.pk
Sign in
|
Join
|
Help
Search
Nasir Ali Khan
Believing is easier than thinking. Hence so many more believers than thinkers.
Home
Email
About
RSS 2.0
Atom 1.0
Recent Posts
First look at ASP.NET 4.0
Windows Live Communications Platform has stopped working
Google Music Search Feature, Rocks!!!
2012 the beginning of end?
Microsoft offer 15-25% discount on various exams
Tags
.NET framework
ADO.NET
ASP.NET 2.0
C#
Cosmology
General Thoughts
Google
Microsoft Technologies
Science & Technology
Sociology
Sports
SQL Server
Web Applications
Web Technologies
Windoz Applications
Navigation
Home
Blogs
Forums
Photos
Downloads
My Reader
Control Panel
Archives
November 2009 (2)
October 2009 (4)
September 2009 (2)
May 2009 (1)
January 2009 (2)
November 2008 (1)
October 2008 (7)
September 2008 (4)
July 2008 (4)
June 2008 (2)
May 2008 (8)
April 2008 (2)
March 2008 (8)
February 2008 (16)
January 2008 (6)
December 2007 (5)
November 2007 (3)
October 2007 (2)
September 2007 (2)
August 2007 (7)
July 2007 (3)
June 2007 (8)
February 2007 (3)
November 2006 (1)
September 2006 (1)
July 2006 (2)
June 2006 (1)
May 2006 (3)
April 2006 (3)
March 2006 (4)
February 2006 (5)
December 2005 (2)
November 2005 (2)
October 2005 (2)
September 2005 (6)
August 2005 (5)
July 2005 (3)
June 2005 (6)
May 2005 (8)
April 2005 (4)
March 2005 (2)
February 2005 (5)
January 2005 (4)
Application Domain, a .NET way of Isolating Applications
Intended Readers
: Persons having intermediate knowledge of processes, threads
Level
: Expert
Introduction
Application domain is the boundary with in which an application runs. This is similar to process that we have in traditional applications. Application domain provides isolation so that application running in one domain can’t affect the other domains. This approach provides flexibility and the options for the developers to create secure and robust applications.
One process can contain multiple application domains; application running in one domain can’t directly access the code/data of other. Proxy object is needed to accomplish this and Marshaling is required in inter App domain communication. This isolation of app domains ensures that the failure of application in one domain doesn’t affect other domains in the process.
Benefits of Application Domain
Application having similar OS resources can be aggregated but isolated in one process through application domain, results efficient utilize of system resources.
Inter process communication is much more expensive compared to inter app domain communication, so its better to run two related application in separate domain rather that separate process.
Application domain can be create, executes dynamically at run time allows greater application scalability and manageability as compared to process operations which are quite expensive.
Example 1
class
Class1
{
[STAThread]
static
void
Main(
string
[] args)
{
AppDomain otherDomain =
AppDomain.CreateDomain("MyDomain");
MyTarget(); // call method within current domain
// call method within the context of otherDomain
otherDomain.DoCallBack(
new
CrossAppDomainDelegate(MyTarget));
}
public
static
void
MyTarget()
{
Console.WriteLine("My Target called, within the domain " +
AppDomain.CurrentDomain.FriendlyName);
}
}
The above code is quite self explanatory, in the main method we create a domain named “MyDomain”, after this I called MyTarget method in default domain and then in the newly created domain.
Example 2
AppDomain2.exe
class
Class1
{
[STAThread]
static
void
Main(
string
[] args)
{
Console.WriteLine("This is application domain 2");
Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);
}
}
AppDomain1.exe
static
void
Main(
string
[] args)
{
Console.WriteLine("Main Assembly is executing...");
AppDomain otherDomain =
AppDomain.CreateDomain("MyDomain");
// directly executes the main method of assembly
otherDomain.ExecuteAssembly(@"…\Debug\TrpAppDomain2.exe");
}
Since this is single threaded application that’s why execution flow is sequential in both domains, multi threaded application uses app domains powers even more.
Your comments and feedbacks are always welcome
Posted:
Saturday, May 28, 2005 7:29 PM by
nasir
Comments
khurram
said:
How do you compare App Domains with traditional way of creating thread and running it? In .NET we can have an associated IPrinciple for security purposes.
#
May 28, 2005 8:25 PM
Anonymous comments are disabled