小编waz*_*lin的帖子

AppDomain 未处理的异常

有很多话题涵盖了这个问题。但是我还是有问题。

我将程序集加载到 new 中,AppDomain如下所示:

public void Run()
{
    //There's the problem.
    //As Panos Rontogiannis mentioned the thread is created in default AppDomain
    new Thread(RunApp).Start();
}

private void RunApp()
    try
    {
        AppDomain.CreateDomain("domain name").ExecuteAssembly("path to assembly");
    }
    catch (Exception _e)
    {
        MessageBox.Show("Unhandled Exception.\n" + _e);
    }
}
Run Code Online (Sandbox Code Playgroud)

在加载的程序集的 Main 方法中,我将处理程序订阅到UnhandledException事件:

AppDomain.CurrentDomain.UnhandledException += handleException;
Run Code Online (Sandbox Code Playgroud)

处理程序本身:

public static void handleException(object a_s, UnhandledExceptionEventArgs a_args)
{
    var _e = (Exception)a_args.ExceptionObject;
    //Static loger class method
    Loger.WriteError(_e.GetType().ToString(), _e.Message, "default solution");
}
Run Code Online (Sandbox Code Playgroud)

但是在加载的程序集中抛出异常的任何地方都不会涉及处理程序。我只在默认AppDomain(第一个 …

c# exception-handling appdomain

5
推荐指数
1
解决办法
7975
查看次数

跨控制台访问Console.Out

我需要从应用程序(Core.exe)读取标准输出,该输出在同一进程中运行但在不同的appDomain中运行.在处理流程时重定向输出很容易,但appDomains概念对我来说是新的.

所以..我开始在isolataed appDomain中应用程序

new HostedApp("core", "Core.exe").Run();

class HostedApp
{
    internal string DomainName;
    internal string AssemblyName;
    internal AppDomain Ad;
    internal Thread AppThrd;

    public HostedApp(string a_domain, string a_assemblyName)
    {
        DomainName = a_domain;
        AssemblyName = a_assemblyName;
        Ad = AppDomain.CreateDomain(a_domain);
    }

    public void Run()
    {
        AppThrd = new Thread(RunApp);
        AppThrd.Start();
    }

    private void RunApp()
    {
        try
        {
            Ad.ExecuteAssembly(AssemblyName);
        }
        catch(Exception _ex)
        {
            MessageBox.Show("Unhandled exception\n" + _ex);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图重定向当前进程的Console.Out,假设如果应用程序共享相同的进程,则会有单个标准输出.

但它只显示默认的appDomain标准输出.

所以,总结一下,我需要访问另一个appDomain应用程序标准输出.或者可能有一种方法从"核心"appDomain调用位于默认appDomain中的方法?

c# appdomain

2
推荐指数
1
解决办法
2192
查看次数

标签 统计

appdomain ×2

c# ×2

exception-handling ×1