速度 - 优化Windows窗体应用程序 [英] Speed-optimise a Windows Forms application

查看:158
本文介绍了速度 - 优化Windows窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何加快优化Windows窗体应用程序?

How do I speed optimize Windows Forms applications?

我说的不是显而易见的。NET的优化技术 - 如 NGEN -ing,缓存对象等我已经试过了,什么我最多是从1500 NBSP减少的形式动初始化时间,毫秒到500 NBSP;毫秒

I am not talking about apparent .NET optimisation techniques - like NGEN-ing, caching objects, etc. I already tried that and what I am up to is to reduce the form initilization time from a 1500 msec down to 500 msec.

剖析确定了最慢的code和几乎全部是在的InitializeComponent ,并在此方法中最慢的线条

Profiling has identified the slowest code and almost all of it is in the InitializeComponent, and within this method the slowest lines is

  1. 创建(只是新荷兰国际集团)WebBrowser组件的
  2. 从资源加载图标(可怕的500 NBSP;毫秒)
  3. 创作的 ContextStripMenu
  4. 若干 this.Controls.Add()通话贡献了很多了。
  1. creation of the (just new-ing) WebBrowser component
  2. loading icon from a resource (hideous 500 msec)
  3. creation of the ContextStripMenu
  4. several this.Controls.Add() calls contribute a lot too.

目前,我只能看看如何解决点(2) - 被存储​​为嵌入的资源,以私有字段移动图标数据(例如,的 Base64的克斯codeD字符串)。

At the moment, I can only see how to fix point (2) - move icon data from being stored as embedded resource to a private field (for example, Base64-encoded string).

什么是我应该做点1,3和4?

What what should I do with points 1, 3 and 4?

推荐答案

如果这不是主要形式,创建形式为隐藏在另一个线程,并显示它的时候了,当用户要求它。

If this is not the main form, create the form as hidden in another thread and show it right away when user asks for it.

如果它的主要形式,你可以使用多线程仍然初始化平行对照:web浏览器中的一个线索,在另一图标,在另一个等带状菜单,但形式仍然需要隐藏我想在多线程窗口消息可以迷惑的事情。

If it's the main form you can still initialize the controls in parallel using multithreading: webbrowser in a thread, icons in another, strip menu in another etc. But form still needs to be hidden I guess as Window messages in multiple threads can confuse things.

另外你还可能需要做Controls.Add被部分在主线程中的控件集合可能不是线程安全的。

Also you might still need to do "controls.add" part in the main thread as Controls collection may not be thread-safe.

这篇关于速度 - 优化Windows窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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