开发者

Preloading Winforms using a Stack and Hidden Form

I am currently working on a project where we have a couple very control heavy user controls that are being used inside a MDI Controller. This is a Line of Business app and it is very data driven.

The problem that we were facing was the aforementioned controls would load very very slowly, we dipped our toes into the waters of multi-threading for the control loading but that was not a solution for a plethora of reasons. Our solution to increasing the performance of the controls ended up being to 'pre-load' the forms onto a hidden window, create a stack of the existing forms, and pop off of the stack as the user requested a form.

Now the current issue that I'm seeing that will arise as we push this 'fix' out to our testers, and the ultimately our users is this:

Currently the 'hidden' window that contains the preloaded forms is visible in task manager, and can be shut down thus causing all of the controls to be lost. Then you have to create them on the fly losing the performance increase. Secondly, when the user uses up the stack we lose the performance increase (current solution to this is discussed below).

For the first problem, is there a way to hide this window from task manager, per开发者_JAVA技巧haps by creating a parent form that encapsulates both the main form for the program and the hidden form?

Our current solution to the second problem is to have an inactivity timer that when it fires checks the stacks for the forms, and loads a new form onto the stack if it isn't full. However this still has the potential of causing a hang in the UI while it creates the forms. A possible solutions for this would be to put 'used' forms back onto the stack, but I feel like there may be a better way.

EDIT: For control design clarification

From the comments I have realized there is a lack of clarity on what exactly the control is doing.

Here is a detailed explanation of one of the controls.

I have defined for this control loading time as the time it takes from when a user performs an action that would open a control, until the time a control is accessible to be edited.

The control is for entering Prescriptions for a patient in the system, it has about 5 tabbed groups with a total of about 180 controls. The user selects to open a new Prescription control from inside the main program, this control is loaded into the MDI Child area of the Main Form (which is a DevExpress Ribbon Control). From the time the user clicks New (or loads an existing record) until the control is visible. The list of actions that happens in the program is this:

The stack is checked for the existence of a control. If the control exists it is popped off of the stack. The control is rendered on screen. This is what takes 2 seconds The control then is populated with a blank object, or with existing data. The control is ready to use.

The average percentage of loading time, across about 10 different machines, with different hardware the control rendering takes about 85 - 95 percent of the control loading time.

Without using the stack the control takes about 2 seconds to load, with the stack it takes about .8 seconds, this second time is acceptable.

I have looked at Henry's link and I had previously already implemented the applicable suggestions.

Again I re-iterate my question as What is the best method to move controls to and from the stack with as little UI interruption as possible?


12 Tips To Speed-up Your Windows Forms Applications
http://devcomponents.com/blog/?p=361

...contains some good tips. I would exhaust these first.

If you really are extremely data-driven, I would make sure that you're doing the usual things to ensure speed, like SELECTing only the columns you need, and making judicious use of stored procedures. Check your database practices; make sure you have indexes where you need them. Profile your data requests; find out which ones are the slowest, and optimize them.

There's a good chance that you are spending 80% to 90% of your time on 10% to 20% of your form's activity. Find out where these pain points are, and focus on them.


Our solution to increasing the performance of the controls ended up being to 'pre-load' the forms onto a hidden window, create a stack of the existing forms, and pop off of the stack as the user requested a form.

What do you mean by "pre-load the forms onto a hidden window"?

Using the .NET object model, you should be able to instance as many forms as needed, keeping track of them in a generic collection, such as a list, and simply setting the .Visible and .MDIParent properties as needed.

Our current solution to the second problem is to have an inactivity timer that when it fires checks the stacks for the forms, and loads a new form onto the stack if it isn't full.

Why are these forms being destroyed? Can't they be cleared and re-used?


For the task bar, winforms have a property that is called "ShowInTaskBar" Set it to false. As for threading all of your data manipulation should be on it's own thread/threads. Also not sure if it would help, but there is also a doublebuffering property on form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜