发送消息到原始应用程序域
我有一个应用程序创建一个新的应用程序域,如下所示:
private static AppDomain domain = null;
private static void LoadAndLaunchAppDomain(string assemblyFile, string typeName)
{
AppDomainSetup setup = new AppDomainSetup()
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ShadowCopyFiles = "true"
};
domain = AppDomain.CreateDomain("ClientKernel", null, setup);
domain.UnhandledException += new UnhandledExceptionEventHandler(domain_UnhandledException);
ClientKernelLauncher launcher = (ClientKernelLauncher)domain.CreateInstanceFromAndUnwrap(assemblyFile, typeName);
launcher.Launch();
}
static void domain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// handler
}
在某些时候抛出异常并且流到达处理程序内部。我真正想要的是在发生这种情况时重新创建域。我注意到处理程序实际上是在“ClientKernel”应用程序域上运行,而不是在创建它的原始域上运行。
如何与原始域通信并告诉它再次调用 LoadAndLaunchAppDomain()
方法?
I have an application that creates a new app domain like this:
private static AppDomain domain = null;
private static void LoadAndLaunchAppDomain(string assemblyFile, string typeName)
{
AppDomainSetup setup = new AppDomainSetup()
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ShadowCopyFiles = "true"
};
domain = AppDomain.CreateDomain("ClientKernel", null, setup);
domain.UnhandledException += new UnhandledExceptionEventHandler(domain_UnhandledException);
ClientKernelLauncher launcher = (ClientKernelLauncher)domain.CreateInstanceFromAndUnwrap(assemblyFile, typeName);
launcher.Launch();
}
static void domain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// handler
}
At some point an exception is thrown and the flow reaches inside the HANDLER. What I actually want is to recreate the domain when this happens. What I noticed is that the handler is actually running on the "ClientKernel" app domain and not the original domain that created it.
How can communicate back to the original domain and tell it to call again the LoadAndLaunchAppDomain()
method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
AppDomain.DoCallBack()
调用另一个 AppDomain 上的方法。我不确定一旦调用
AppDomain
时抛出未处理的异常,这是否会起作用。但是,你可以尝试一下。Use
AppDomain.DoCallBack()
to call a method on anotherAppDomain
.I am not sure if that will work once an unhandled exception is thrown in calling
AppDomain
. But, you could give it a shot.像这样的东西会起作用吗?
我不知道托管代码的类的名称是什么,因此您需要将 SomeStaticClass 更改为正确的类名称。
Would something like this work?
I don't know what the name of your class hosting the code is so you'll need to change SomeStaticClass to the right class name.