Slow performance creating buttons for UltraToolbar

Posted by Tung on 24-Jul-2012 09:46

Hi

In my main menu form, I'm using the UltraToolbarsManager and dynamically creating toolbars and buttontools. Here's what I do:

Create an UltraToolbar.

In a loop, create ButtonTools and store them in a Toolbase array.

Using AddRange, add the array to the toolbar manager and the new toolbar.

And repeat for each toolbar.

It works fine but it's slow, specifically when it creates the buttontools. It takes over 2 seconds to create 35 buttons. I'm also using an UltraTree and that creates over 700 nodes in about 0.15 seconds.

I changed the code from using Add to AddRange and added an index to the temp-table that holds the data, which improved things a bit.

Does anyone know any other ways to make it quicker?

Thanks

Tung

All Replies

Posted by Admin on 24-Jul-2012 12:06

Does anyone know any other ways to make it quicker?

 

Use the BeginUpdate() and EndUpdate method of the UltraToolbarsManager around your code.

Posted by Tung on 25-Jul-2012 03:07

Good suggestion, but I should have mentioned I'm already doing that.

My next idea is to use the System.Windows.Forms.Application:Idle event, it's not bad. I create empty toolbars in the constructor. After the form is shown and while the user isn't doing anything, the Idle method creates the buttontools and adds them to the toolbars.

Posted by Admin on 25-Jul-2012 03:16

Good suggestion, but I should have mentioned I'm already doing that.

 

In that case the result is pretty strange. I create way larger menu/toolbar/ribbon structures in way less time.

The Idle event doesn’t make things really faster - I may just appear to be faster. Are you loading images at the same time? From a local path or the network?

Posted by Tung on 25-Jul-2012 05:28

Well spotted, I should've posted the code I'm using. The images are stored on a network drive.


cImagePath = SEARCH(ttMenu.btn-up).
IF cImagePath NE ? THEN
ASSIGN oButtonTool:SharedProps:AppearancesSmall:Appearance:Image = Bitmap:FromFile(cImagePath)
oButtonTool:SharedProps:AppearancesLarge:Appearance:Image = Bitmap:FromFile(cImagePath).

Without that, it drops to 60 ms!

I could use an ImageList with preloaded images. If a menu's image was created by the client, I can use the above code else I get it from the ImageList's collection.

I understand your point about the Idle event, that's what I wanted users to think if I couldn't create buttontools any quicker.

Edit:

I've tested a coule of things.

Using an ImageList, it takes 0.9 - 1.1 secs.

If I replace the Bitmap:FromFile(cImagePath) with NEW Bitmap(cImagePath), it's 1.0 - 1.2 secs.

So it's down from over 2 secs but I'd like to make it under 0.5 sec.

Posted by Tung on 25-Jul-2012 08:10

I've found the problem. It's nothing to do with the toolbar or ButtonTools, the SEARCH function is the cause.

If I run SEARCH only when the image isn't in the ImageList, it drops to 180ms.

I never realised it hit performance that badly, I'm going to remember that in future.

Posted by Admin on 25-Jul-2012 08:16

If I run SEARCH only when the image isn't in the ImageList, it drops to 180ms.

 

I figure you have way more than a single network folder in your propath? That's slowing everything down!

Posted by Tung on 25-Jul-2012 08:19

Luckily it only affects our developers. Our clients have a single folder for compiled code, icons, etc.

This thread is closed