Can anyone explain me why C# event handlers are slowing down the form startup?

G

G. Tarazi

Hi



Create a schema using vs.net with 100 text fields, simple fields with the name of A00 to A99



Create an InfoPath form using VS.NET 2003 SP1 C#, and import that schema to the form.



Create a c# event handler (on after change) for each filed, and keep it with the default code.



Compile and publish the form, then disable the event handlers (by commenting them) and recompile and publish the form with a new name.



Publish it to the desktop



Double click on the first published form, and then on the second published form.



The one with the C# event handlers, will eat the CPU speed, on a 3GHz Intel, 1GB ram for 2 seconds, and then will open.



The one with the event handlers disabled will not do that.



Repeat the entire test with a form with Java Script, you will be amazed from the results, the form will open instantly.



Now my problem is when there is code inside these event handlers, in my real world form, the form talks about 15-20 seconds full CPU speed at 100 present on the same machine, when double clicked before it opens.



And that just because there is code inside the event handlers and that code is written in a way not to be called during startup, and I verified that function by function the past 2 days.



If I comment half of them, the seeped will increase to the half. (7-10sec 100% cpu)



Why?



I am just not getting it, why it is happening? Why that form eats the CPU speed when it's C# and not doing it when Jscript?


Thank you
 
R

Rob

I would expect it to be slow if it was compiled in "Debug". Try compiling in
"Release" and see what happens.
 
G

G. Tarazi

No, this is not the problem, it was the first thing that I tried, the
problem is more clear today to me, InfoPath itself is taking huge amount of
time to bind the C# event handlers to the form, at least this is my
conclusion by now.



I came to it after creating a new form, importing the existing schema,
coping and pasting all event handlers, then empting them, and keeping only
this code



if (e.IsUndoRedo) return;

if(e.Operation == "Insert")

{

}



The results, is 9-10 seconds for the published empty form to open, when the
event handlers are disabled the problem is gone.



Rob said:
I would expect it to be slow if it was compiled in "Debug". Try compiling in
"Release" and see what happens.
real world form, the form talks about 15-20 seconds full CPU speed at 100
present on the same machine, when double clicked before it opens.code is written in a way not to be called during startup, and I verified
that function by function the past 2 days.
 
R

Rob

Interesting, I have done the same exact thing but with fewer fields, 20-25
without any difference. Can the form be broken down into multiple forms?

- Rob
 
G

G. Tarazi

We wrote our own tool that will build 19 different forms from the existing
form; the main form is split on views, and it's easy to generate an xsl and
xsf with the rest of the files from it.



But what is the point, if a total empty form takes 10 seconds (just schema
and empty event handlers) to open (not load data) just open in the screen
empty, no design!, blank page
 
G

G. Tarazi

Forgot to say, the dll file behind is the same, all the forms will share the
same dll file, and the event handlers are in this dll file :)
 

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