Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would handle the exceptions in the remote application domain. First I would create a new assembly with the exception handling code and then I would load it into child application domain.</p> <p>The following code should give some ideas.</p> <pre><code>class Program { private class NonSerializableException : Exception { } static void Main(string[] args) { var childAppDomain = AppDomain.CreateDomain("Child"); Console.WriteLine("Created child AppDomain #{0}.", childAppDomain.Id); // I did not create a new assembly for the helper class because I am lazy :) var helperAssemblyLocation = typeof(AppDomainHelper).Assembly.Location; var helper = (AppDomainHelper)childAppDomain.CreateInstanceFromAndUnwrap( helperAssemblyLocation, typeof(AppDomainHelper).FullName); helper.Initialize(UnloadHelper.Instance); childAppDomain.DoCallBack( () =&gt; new Thread(delegate() { throw new NonSerializableException(); }).Start()); Console.ReadLine(); } private sealed class UnloadHelper : MarshalByRefObject, IAppDomainUnloader { public static readonly UnloadHelper Instance = new UnloadHelper(); private UnloadHelper() { } public override object InitializeLifetimeService() { return null; } public void RequestUnload(int id) { // Add application domain identified by id into unload queue. Console.WriteLine("AppDomain #{0} requests unload.", id); } } } // These two types could be in another helper assembly public interface IAppDomainUnloader { void RequestUnload(int id); } public sealed class AppDomainHelper : MarshalByRefObject { public void Initialize(IAppDomainUnloader unloader) { AppDomain.CurrentDomain.UnhandledException += (sender, e) =&gt; unloader.RequestUnload(AppDomain.CurrentDomain.Id); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload