What is an AppDomain? What are the benefits of AppDomains or why Microsoft brought the concept of AppDomains, what was the problem without AppDomains?
Please elaborate.
What is an AppDomain? What are the benefits of AppDomains or why Microsoft brought the concept of AppDomains, what was the problem without AppDomains?
Please elaborate.
An AppDomain
provides a layer of isolation within a process. Everything you usually think of as "per program" (static variables etc) is actually per-AppDomain. This is useful for:
AppDomain
, but not an assembly within an AppDomain
)The pain is you need to use remoting etc.
See MSDN for lots more info. To be honest, it isn't something you need to mess with very often.
AppDomains can be viewed as lightweight processes. They share many of the same characteristics of a process, e.g. they have their own copies of statics, assemblies and so forth, but they are contained within a single process. From the operating system's point of view a process is just a process no matter how many AppDomains it may contain.
Unlike a process however, an AppDomain does not have any threads unless you explicitly create them. A thread can run code in any AppDomain.
AppDomains are part of the same process and thus actually share the same managed heap. This is usually not an issue since the AppDomain programming model prevents implicit access between AppDomains. However, some references are actually shared between AppDomains such as type objects and interned strings.
Take a look at this - that might explain it:
http://blog.flair-systems.com/2010/05/c-fastfood-what-appdomain.html
When 10 users browse a page say (login.aspx) in a published website,
ASP.Net Worker Process (w3wp.exe) creates 10 application domains to host the page assembly into it for each client, thus creates 10 appDomains.
appDomain: assembly App_Web_Login.aspx.fdf7a39c.dll So, what’s the story? When run any application, the operating system hosts it in a process
(p1) to be ran by the processor . and if the run another different application(OS hosts it into another process (p2)).if app1 wants to access an assembly (dll or exe) form app2, the accessing will be managed by OS which is slow.
The another solution:- Host the assemblies you want into an application domain (which is a
logical boundary you create to host many assemblies as you wish). the appDomain is managed by .net framework but process is managed by the operating system (which is slower)
Operating system: Process1 appDomain1 assembly App_Web_Login.aspx.fdf7a39c.dll assembly DataAccessLayer.dll appDomain2 assembly App_Web_EmployeeData.aspx.fdf7a39c.dll