Slow drawing speed of WinForms (esp via COM interop)

P

Phil

Hi,

Has anybody experienced severe slow-down with the drawing speed of
WinForms? It's not fast at the best of time, but the particular
scenario I am having problems with is via COM interop and Excel.

The structure is:


Excel VBA macro
|
V
instantiate and call a COM wrapper class exposed
by my assembly using ComVisible(true)
|
V
Wrapper class instantiates the WinForm
and displays it


The forms don't do anything special, they contain maybe 10-20
controls, including one or two grids, but you can sit there and watch
them paint themselves control-by-control.


I am using data binding, if that helps.

Any help to fix this will be very gratefully received, but even if you
have experienced something similar please reply so that I know I am
not alone!
 
P

Patrice

COM Interop is slow. I would minimize the number of calls (what is the
source you databind ?, do you have a single call to the .NET application ?).

I made something the other way round i..e uisng Excel from Windows. I's much
quicker :
- to copy data to Excel using a single cell (as an array) instead of copying
all separately
- to have the winform to create an Excel macro that is then transmitted and
executed in Excel (quicker than performing the layout from the Winforms with
the associated overhead for each call).
 
G

Guest

Hi Phil,

In cases like that, I often display the form first, without the
"databinding". In the Form_LOad event, I activate a Forms Timer with an
interval of maybe 20 ms, and then when the timer elapses I fill in all the
controls (and disable the timer to make sure it only elapses once). This
speeds up the loading of the form and the painting, so the user sees an empty
screen much faster. Then the data is loaded with a small delay, ususally not
disturbing for the user.

This doesn't make it faster, but it looks faster and certainly much nicer,
and it is a much better experienc for the user.

Hope this helps,

Joris
 
P

Phil

COM Interop is slow. I would minimize the number of calls (what is the
source you databind ?, do you have a single call to the .NET application ?).
Patrice,

Yes, just essentially a call to ShowDialog(). I am gonna try it from
other applications eg a VB6 and see if that makes a difference, it
might be an Excel-specific problem.
 
P

Phil

Hi Phil,

In cases like that, I often display the form first, without the
"databinding". In the Form_LOad event, I activate a Forms Timer with an
interval of maybe 20 ms, and then when the timer elapses I fill in all the
controls (and disable the timer to make sure it only elapses once). This
speeds up the loading of the form and the painting, so the user sees an empty
screen much faster. Then the data is loaded with a small delay, ususally not
disturbing for the user.

This doesn't make it faster, but it looks faster and certainly much nicer,
and it is a much better experienc for the user.

Hope this helps,

Joris

Joris,

I'll try it later this week (have to get ready for a demo now....)
Thanks for the suggestion.
 
P

Patrice

What I don't understand for now is if Excel is involved in the picture. Does
Excel just launch the form and the rest of the whole process is internal.
What is the source of the bindings ?

If 2.0 you can try Joris's suggestion with the "Shown" event...
 
P

Phil

What I don't understand for now is if Excel is involved in the picture. Does
Excel just launch the form and the rest of the whole process is internal.

Yes, exactly. There are 2 lines of VBA behind a button in Excel.
What is the source of the bindings ?

A typed DataSet - which has been loaded before the form is shown. I
have basically written an overload of ShowDialog() that does this:

public void ShowDialog(string SalesOrderNum) {
load the dataset with 1 order for SalesOrderNum
initialise data bindings
set form caption to "New Order" or "Edit Order"
ShowDialog(); // call standard form ShowDialog to display the window
}

So I am doing the majority of my work *before* I call ShowDialog, so I
am surprised at the slow painting, everything should be there by then.

It may be that I should use the events....perhaps doing it the way I
am is non-standard and is causing the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top