发送消息到原始应用程序域

发布于 2024-10-08 15:40:25 字数 920 浏览 0 评论 0原文

我有一个应用程序创建一个新的应用程序域,如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2024-10-15 15:40:25

使用 AppDomain.DoCallBack() 调用另一个 AppDomain 上的方法。

我不确定一旦调用 AppDomain 时抛出未处理的异常,这是否会起作用。但是,你可以尝试一下。

Use AppDomain.DoCallBack() to call a method on another AppDomain.

I am not sure if that will work once an unhandled exception is thrown in calling AppDomain. But, you could give it a shot.

披肩女神 2024-10-15 15:40:25

像这样的东西会起作用吗?

AppDomain hostDomain = AppDomain.CurrentDomain;
domain = AppDomain.CreateDomain("ClientKernel", null, setup);
domain.UnhandledException += (s, e) => {
   hostDomain.DoCallBack(() => { SomeStaticClass.LoadAndLaunchAppDomain("someAssembly", "someClassName"); }
}

我不知道托管代码的类的名称是什么,因此您需要将 SomeStaticClass 更改为正确的类名称。

Would something like this work?

AppDomain hostDomain = AppDomain.CurrentDomain;
domain = AppDomain.CreateDomain("ClientKernel", null, setup);
domain.UnhandledException += (s, e) => {
   hostDomain.DoCallBack(() => { SomeStaticClass.LoadAndLaunchAppDomain("someAssembly", "someClassName"); }
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文