I am working on my MCTS and am currently studying the functionality of AppDomain. But I come across something incomprehensible. AppDomainmust capture Exceptionand allow the domain to safely unload. (Except, perhaps StackOverflowException, as suggested elsewhere)
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
Evidence adevidence = AppDomain.CurrentDomain.Evidence;
domain.UnhandledException += new UnhandledExceptionEventHandler(domain_UnhandledException);
AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence, setup);
When I decide to instantiate the example class in the assembly created for this purpose, I have to get a secure, limited domain that will capture errors that occur and can be safely unloaded. At least that’s how I understand it from my study book.
var type = (IDoSomeWork) domain.CreateInstanceAndUnwrap("Library1", "Library1.Class1");
type.Run();
This throws an exception, but on type.Run()(since I did it this way). But shouldn't it be AppDomainsafe to capture him? Doesn't that mean what we have AppDomain?
UPDATE:
Library1.Class1. , , UnhandledExceptionEventHandler .
[Serializable]
public class Class1 : MarshalByRefObject, IDoSomeWork
{
public void Run()
{
Debug.WriteLine(AppDomain.CurrentDomain.FriendlyName);
throw new ApplicationException(String.Format("{0}", this.ToString()));
}
}
, MyDomain.