本文介绍了如何快速加载一个WinForms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序。主要形式有很多的控制,这是的,它使加载速度很慢的原因之一。我想做的就是让窗体加载速度更快。

I have a winforms application. the main form is has a lot of controls and that is one of the reason that makes it load very slow. what I would like to do is to make the form load faster.

我已经设置了的BeginUpdate和endupdate。的形式不被呈现在后台工作线程,因为这是主模。有没有最初的形式。当用户点击应用程序图标,这是加载了第一种形式。添加一个进度条或任何形式的飞溅是不是对我来说是个好主意。

I have set the beginupdate and endupdate. The form is not being rendered in the background worker thread, because this is the main form. There are no initial forms. When the user clicks the application icon, this is the first form that loads up. Adding a progress bar or any splash form is not a good idea for me.

我已签在这里堆栈溢出等问题,但他们似乎并不像我一样面对同样的问题。

I have checked other questions here on Stack overflow but they do not seem to face the same problem as I do.

如果有你心里有一些例子/想法,这将是很好的你,如果你能和我一起分享。

If there are some examples/ideas you have in mind, it would be nice of you if you can share it with me.

感谢和问候
加甘扬尤亚

Thanks and RegardsGagan Janjua

推荐答案

一个几点建议:


  • 尽量减少你的用户界面的复杂性。你的用户会感谢你,你就会有更少的控制加载。例如,如果您有不经常使用3或4的控制,可以将它们移动到对话框或折叠式窗体的先进的部分,所以你可以推迟创建/显示他们?是否所有所需的控制?真?想想你正在努力实现工作流程 - 是当前的一组控件实现工作流程最简单的方法?完成所有的控制需要一次显示?也许你可以将它们放在单独的标签在标签控件(因此只actuallyl创建控件显示在选项卡)?

  • Try to minimise the complexity of your UI. Your users will thank you and you'll have fewer controls to load. For example, if you have 3 or 4 controls that are not used often, can you move them into a dialog or fold-out "advanced" section of your form, so you can defer creating/showing them? Are all the controls needed? Really? Think about the workflow you are trying to achieve - is the current set of controls the simplest way to achieve the workflow? DO all the controls need to be shown at once? Perhaps you could place them on to separate tabs in a tab control (and thus only actuallyl create the controls as the tab is shown)?

可以减少控制类型的范围内使用?每一个新的类型的控制可能会导致程序加载了一个新的DLL来支持它。有每个DLL被初始化造成额外的启动时间。

Can you reduce the range of control types used? Each new type of control may cause your program to load up a new dll to support it. Every dll that has to be initialised causes extra startup time.

您使用的是慢速启动任何控件?一个简单的文本字段将是快,但复杂的图形控制可能会很慢。

Are you using any controls that are slow to start up? A simple text field will be fast, but a complex graphing control may be slow.

有多少组件(自己的)被加载? (与ILMerge如)将所有的代码放到一个单独的组件和加载时间可能会提高不少。

How many assemblies (of your own) are loaded? Combine all the code into a single assembly (e.g. with ILMerge) and load times will probably improve quite a bit.

删除不需要任何初始化代码。可以简化初始化?可以在任何初始化推迟(例如只创建一些成员变量时,实际上需要一个数据出现的第一个按钮,用户点击,不要试图建立与数据库的连接,如果它不是真正需要的是,等)

Remove any initialisation code that isn't needed. Can you simplify the initialisation? Can any initialisation be deferred (e.g. only create some member variables when the user clicks on the first button that actually needs that data to be present, Don't try to create a connection to a database if it's not actually needed yet, etc)

可以推迟(部分)的创建用户界面?例如,你可以到一组控件放入一个单独的用户控件的形式,然后再启动(例如在一个定时器)后不久,编程方式添加这个表单,MainForm的。这将使你的MainForm很快出现,然后被填充后不久,有更多的控制,这可能不会提高实际的启动时间,但它会感觉快了很多,反应更迅速启动。 (这种方法也可以非常有效的,如果你的MainForm卷轴和这些额外的控制是最初并不在屏幕上,因为他们只需要创建如果用户滚动足以下来看看他们)

Can you defer creation of (some of) the UI? For example, you may be able to place a group of controls into a separate UserControl form, and then add this form programmatically to your MainForm shortly after startup (e.g. on a Timer). This will allow your MainForm to appear very quickly, and then be "populated" shortly after with additional controls, which may not improve the actual startup time, but it will "feel" a lot faster and more responsive to start up. (This approach can also be extremely effective if your MainForm scrolls and those extra controls are initially not on-screen, as they only need to be created if the user scrolls down enough to see them)

您显示这可能是缓慢的加载(如大的位图图像或数据从SQL服务器获取)的信息吗?你可以推迟他们的加载或运行它作为一个后台线程?使用压缩加快加载?降低其分辨率,以尽量减少必须加载的数据量?处理前数据并将其存储在一个快速启动缓存的程序运行下一次?

Are you displaying any information that might be slow to load (e.g. large bitmap images or data fetched from an SQL server)? Can you defer the loading of them or run it as a background thread? Use compression to speed up loading? Reduce their resolution to minimise the amount of data that must be loaded? Pre-process data and store it in a quick-start cache for the next time the program is run?

可以将某些控件被优化的方法所取代?例如您可以创建一个按钮栏为一组10个独立控制,或作为与10个按钮的外观iself绘制一个单一的控制。这是很容易使一个控制INITIALISE和重绘速度超过10个独立的控制。

Can some controls be replaced by an optimised approach? e.g. You can create a "button bar" as a set of 10 separate controls, or as a single control that draws iself with the appearance of 10 buttons. It's much easier to make the single control initialise and redraw faster than 10 separate controls.

当然,一旦最明显的低挂水果已收集(甚至之前):

And of course, once the most obvious low-hanging fruit has been collected (or even before):


  • 事件探查器下运行程序,看到它的消耗时间

这篇关于如何快速加载一个WinForms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:15