I have two app domains, one parent creating the child domain. In the child domain, there is a MarshalByRef
object, being communicated with using .NET Remoting. An object running in the parent domain invokes the wrapper for the remote object as part of the application's function:
public class ScanningTask : Task
{
private class Loader : MarshalByRef
{
public void Load(IEnumerable<string> paths)
{
...
}
public event EventHandler<LoadEventArgs> OnLoad;
}
public void RunTask()
{
var domain = AppDomain.CreateDomain("LoadDomain");
var loader = (Loader)domain.CreateInstanceFromAndUnwrap(
typeof(Loader).Assembly.Location,
typeof(Loader).FullName);
loader.Load(...);
AppDomain.Unload(domain);
}
}
Most code removed for brevity.
This Loader
object exposes an OnLoad
event I'd like to capture in the parent domain. If I just add an event handler delegate, it tries to serialize the ScanningTask
into the child domain and throws an exception about it not being serializable.
What I really want is for the event to be communicated across the domains. Any clever suggestions as to how?