Performance of the FrameworkElementAdapters class

北战南征 提交于 2019-12-13 12:21:53

问题


Can't figure why cross-domain calls is so slow for FrameworkElementAdapters class. Here is a simple code:

class Program
{
    [STAThread]
    static void Main()
    {
        AppDomain domain = AppDomain.CreateDomain("AnotherDomain");

        var instance = (AnotherDomainClass) domain.CreateInstanceAndUnwrap(
            typeof (AnotherDomainClass).Assembly.FullName,
            typeof (AnotherDomainClass).FullName);

        var contract = instance.CreateContract();
    }
}

class AnotherDomainClass : MarshalByRefObject
{
    public INativeHandleContract CreateContract()
    {
        return FrameworkElementAdapters.ViewToContractAdapter(
            new TextBlock());
    }
}

The execution time of the last line instance.CreateContract is near 1.7 sec! Where is a problem?


回答1:


Have you tried decorating your Main method with the LoaderOptimizationAttribute set to LoaderOptimization.MultiDomainHost?

The FrameworkElementAdapters class is part of System.AddIn. Have a look at Add-In Performance: What can you expect as you cross an isolation boundary and how to make it better form the blog of the System.AddIn team. Also have a look at the "Perfomance Optimization" section of the WPF Add-Ins Overview MSDN article.



来源:https://stackoverflow.com/questions/16155189/performance-of-the-frameworkelementadapters-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!