none
What is the need to create our own AppDomains? RRS feed

  • Question

  • Can anyone explain me what is the need to create my own AppDomains when i am provided with defult AppDomains.

    Please explain me using a real time scenario.

    Monday, May 26, 2008 6:36 AM

Answers

  • Hi,

     

    It's good to create an app domain if you want to run code with lower code permissions. Like an addin. I have a piece of software that uses addins so I create an app domain that runs under lower permissions that the rest of the code. This stops a plug in from doing any damage to the machine. So thats one case, when you want to run code in a confined security sandbox.

     

    Another case was using reflection. I have used the configuration file to define a number of DLLs that get loaded and relected at run time. Since the number of DLLs could be potentially huge I load them into a new app domain so when I am finished the app domain can be unloaded. Thats another case, when you need to open and reflect over a large number of DLLs and then want to free up the memory they use.

     

    ASP.NET uses a number of app domains to represent web applications running in ASP.NET. This is another scenario, if you want to have multiple applications running under the same process. For ASP.NET this is it hosting .NET applications but your own application could do something similar.

     

    Another scenario might also be if you want seperate a task from the default application. This way if an exception occurs in the task running on the other app domain then it can be closed without causing the whole application to fail.

     

    Just a couple of examples.
    Monday, May 26, 2008 8:27 AM

All replies

  • Could you please clarify your question?

    Do you want to know how to create AppDomain?

    Or do you want to know what is appropriate scenarion when it is better to create AppDomain?

     

    Monday, May 26, 2008 8:14 AM
  • Hi,

     

    It's good to create an app domain if you want to run code with lower code permissions. Like an addin. I have a piece of software that uses addins so I create an app domain that runs under lower permissions that the rest of the code. This stops a plug in from doing any damage to the machine. So thats one case, when you want to run code in a confined security sandbox.

     

    Another case was using reflection. I have used the configuration file to define a number of DLLs that get loaded and relected at run time. Since the number of DLLs could be potentially huge I load them into a new app domain so when I am finished the app domain can be unloaded. Thats another case, when you need to open and reflect over a large number of DLLs and then want to free up the memory they use.

     

    ASP.NET uses a number of app domains to represent web applications running in ASP.NET. This is another scenario, if you want to have multiple applications running under the same process. For ASP.NET this is it hosting .NET applications but your own application could do something similar.

     

    Another scenario might also be if you want seperate a task from the default application. This way if an exception occurs in the task running on the other app domain then it can be closed without causing the whole application to fail.

     

    Just a couple of examples.
    Monday, May 26, 2008 8:27 AM
  • Two biggies: isolating code in its own domain so it can't destabilize the app and being able to load and unload assemblies at will.  Important to the ASP.NET host and the System.Addin namespace.
    Monday, May 26, 2008 9:19 AM
    Moderator
  • Thanks for your detailed description of many scenarios in which we can create AppDomains.

     

    Monday, May 26, 2008 10:13 AM