WPF插件创建UI策略 [英] WPF Plugin creating UI strategy

查看:80
本文介绍了WPF插件创建UI策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个能够加载某些插件(dll)的应用程序.它正在使用WPF.问题是插件创建UI控件时滞后.

I have an application with ability to load some plugins (dll's). It's working on WPF. The problem is lags when plugin creates UI controls.

在主应用程序中,我有一些控件.我将这些引用传递给插件.当我调用插件的Show()方法时,他必须向我的主应用程序添加特殊的UI控件.

In main application I have some controls. I pass these references to plugin. When I call plugin's Show() method, he must add special UI controls to my main application.

如果主应用程序UI线程无权访问任何在另一个线程中创建的控件,该如何在后台线程中创建插件的UI控件并将其添加到主应用程序中?

How can I create plugin's UI controls in background thread and add their in main application, if main application UI thread don't have access to any control,s wich was created in another thread?

我在主应用程序中使用以下代码:

I use this code in main application:

if (!module.IsInitialized())
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(
                    delegate()
                    {
                        module.InitializeComponents();
                        module.ShowModule();
                    }
                ));
            } 

其中插件的初始化方法是:

where plugin initialize method is:

public void InitializeComponents()
{
MyBodyArea = new SERPBodyArea(); // there is UI control
MyBottomArea = new SERPBottomArea(); // there is UI control
 MyHeaderRibbon = new SERPXamRibbon(); // there is UI control

_IsInitialized = true;
}

因此,当插件创建UI控件时,我的主应用程序被冻结.有什么方法可以在后台线程中创建它并将其添加到主应用程序窗口中?

So when plugin creates UI controls, my main application is frozen. Is thre any way to create it in background thread and add it to main application window?

谢谢.对不起,我的英语不好:(.

Thanks. And sorry for my bad english :(.

推荐答案

您必须继续在UI线程上构造控件,但是可以使它们更轻巧,更精简.通常,这涉及将控件的某些初始化(通常是控件绑定到的数据)推迟到后台线程进行.但是,相同的策略也可以应用于CPU密集型计算或数据结构操作.

You must continue to construct your controls on the UI thread but you can make them more light weight and streamlined. Usually this involves deferring some of the initialization of a control (most often the data the control is bound to) to a background thread. However, the same strategy can apply to CPU-intensive calculations or data structure manipulations.

如果UI线程上完成的实际工作量与屏幕上显示的信息量成正比,则大多数应用程序将非常快速地初始化.您的情况取决于您的控件,因此很难具体说明.

If the amount of actual work that is done on the UI thread is proportional to the amount of information that is displayed on the screen, then most applications will initialize very quickly. Your situation depends on your controls so it is hard to be more specific.

这篇关于WPF插件创建UI策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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