Tuesday, April 6, 2010

How to create appdomain?

In the following cases generally we create an application domain
1. If we create our own runtime host application,
2. If our application needs to create or work with additional application domains that are not automatically generated by the runtime.
3. If the requirement is such that some assemblies have to be managed personally, If this is the case we create our own application domain, load the assemblies that are supposed to be managed personally into application Domain.
AppDomain Class has CreateDomain() method
//To create an app Domain Explicitly
AppDomain.CreateDomain("AppDomainName");
Console.WriteLine(app.FriendlyName); // Displays child domain name
Console.WriteLine(AppDomain.CurrentDomain.FriendlyName); // Displays Host Domain name

Unloading :
When you call a Web service by using SSL and an application domain must be unloaded If the call is in progress, the application domain does not unload, a System.CannotUnloadAppDomainException exception is thrown, and the Microsoft ASP.NET worker process may die. So when we make a call to web service using SSL we explicitly unload the application domain programmatically by AppDomain.Unload method
Note: An application domain may be unloaded for some reason that is unrelated to calling the Web service. For example, if the Web.config file is modified, the application domain may be unloaded

No comments:

Post a Comment