0

I have problems with my current application which is developed in C# with WPF. The application consists of different flowcharts each contained in its own separate window.

At start-up all flowchart classes are instantiated and initialized in their window. Then the windows are made invisible and the flowchart menu appears.

With each new flowchart the application start up gets slower. The window initialization seems to consume a lot of time.

How could I approach this problem?

I thought of initialization when first needed or background initialization.

Note: I forgot a very important fact: The flowchart menu is created based on the other flowcharts, since every single flowchart is rendered as an image in order to display a thumbnail menu button. This is the problem which brough me to the performance impact anyway.

Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143

3 Answers3

2

You have many approaches to this problem. First, you have to remove the initialization from the c'tor.

Where to move it? Either to Window_onLoad event, this way the app will first loaded and then start initializing the flow charts (using a new thread will avoid UI freeze).

Or once the user selects the required flow chart from the menu, you show the window and start initializing the inner flow chart, display a nice "loading.." animation while busy, and show the flow chart once you done.

I'd prefer the second approach, init each object when it's needed.

Edit: Since you have to render the thumbs based on the flowcharts, i would do the following: Move the flowcharts init to the main window Loaded event, and init each flowchart on a different thread, while busy display a nice "please wait.." animation. This way the main app window appears, the user see that the app is loading, your thumbs will be created simultaneously therefore loading time will be reduced. Once all the thumbs created, hide the animation.

MichaelS
  • 7,023
  • 10
  • 51
  • 75
  • That's right, but same as I commented on ChrisF, I have forgot an important fact, which might make this more complicated. I appended it on my original question. – Konrad Reiche Sep 12 '11 at 10:58
0

Don't instantiate all the flowchart classes before you load the main window.

As a first approach I'd go with initialisation when needed.

If this proves to be unpopular as people don't like waiting then go for a background initialisation with the most popular or most recent flowchart instantiated first. This will be right most of the time so the user won't have to wait.

If you need to have a thumbnail of the flowchart then why not save the thumbnail from when the flowchart was last rendered and use that? So, when the flowchart is created first saved save a thumbnail at that point. Then when you populate the list pull that out of the database/off disk and render that.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
0

Nobody's mentioned profiling yet, but why not just try (the last paragraph of) this?

You will easily see the dominant reason for the long time being taken. Chances are, it's something fairly trivial that you can easily fix.

If you want more of an explanation, look here.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135