FrameworkElementAdapters 类的性能 [英] Performance of the FrameworkElementAdapters class

查看:20
本文介绍了FrameworkElementAdapters 类的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法弄清楚为什么FrameworkElementAdapters 类的跨域调用如此缓慢.这是一个简单的代码:

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());
    }
}

最后一行instance.CreateContract的执行时间接近1.7秒!哪里出了问题?

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

推荐答案

您是否尝试过使用 LoaderOptimizationAttribute 设置为 LoaderOptimization.MultiDomainHost?

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

FrameworkElementAdapters 类是 System.AddIn 的一部分.看看 插件性能:当你跨越隔离边界时你会期待什么以及如何制作最好形成 System.AddIn 团队的博客.另请查看 WPF 加载项概述<的性能优化"部分/a> MSDN 文章.

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.

这篇关于FrameworkElementAdapters 类的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆