Performance issues with C# event handlers

D

David

Reading through previous posts, it seems like there is an issue with
performance for C# eventhalder. Is there a work around or fix issued for this
problem?

Can something be done to improve the loading time of the form? I am
receiving a lot of compliants about this, and this may affect development
both of internal applications and sales of SharePoint and Infopath to our
clients.

A fix would be much appreciated.

Thanks
 
G

G. Tarazi

Are you using more than a 100 event handlers on the form?



And are they linked to the schema or to controls (like buttons) on the form?
 
D

David

No I don't have a 100 event handlers, but there are quite a few.

Yes, most event handlers are linked to controls on the form.

David
 
G

G. Tarazi

I had a similar problem, I complaint about it a lot, and it haven't been
fixed yet, but it seams that my problem is a bit different.



Anyway, here is what I had and what I did to fix it.



I have couple of forms, one with 600 controls (text boxes, combo boxes, etc)
and more than 300 event handlers.



These event handlers are linked to controls that are linked directly to the
schema, buttons are not, I also have about 20 button event handlers.



What I realized during the implementation, that the form startup speed is
very slow, I thought the event handlers are getting fired during startup, so
I added an if statement in front of each of them to block them from firing
during the form load.



That helped a bit (I found a bug or 2 in my code), but the form was still
slow, at least 10 seconds to initialize, for the small forms, another big
form took about 1 minute and a half to initialize.



I did more improvements on the code, I found that InfoPath is taking a lot
of time to bind the event handlers to the schema during startup, in my case
it was exactly 19 seconds (in one of the forms), it will take 19 second even
if the event handlers are empty, no code.



Then I realized that this problem is not in the java script version in
InfoPath, so I started converting the C# code to java script, but with no
success, it is like going backwards.



So as a workaround, I've created the 3 possible event handlers, on the top
element of the schema (the data source), and commented all the old event
handlers, and then using if statements, I've started calling functions
instead of the old event handlers, and move the old code to them + fixing
it.



The form become 20 seconds faster, but it was still slow, this time it was
the XML DOM, I was using replace node to replace a megabyte of xml from a
secondary dom to the main dom, I found that this actually is extremely slow,
so I decided to bind some of the controls to the secondary data source, and
I hade some issues there too. (I stoped using the replace node in the xml
dom)



Anyway, the attributes over the c# functions in InfoPath are not working
fine, (the event handlers), they are very slow (when binding them to the
form during startup).



And the dom used by InfoPath is good, but not designed to work with large
amount of xml, the new MSDOM 6.0 was improved a lot, and I guess they will
use it in the next release of InfoPath (just guessing).



Anyway, if you are using any of these, you should be careful with the code.



Good luck
 
D

David

AS you suggested I reduced the number of event handlers to about 7, but the
form is still taking a significant time to load. I have very little XML
manipulation, so I doubt that that would be the issue.

Thanks for your replies though, they appreciated immensely.

As for the MS guys who should be reading this, as a developer I will be
recommeding NOT to use InfoPath with managed code, until performance is
improved significantly. I wish I had at least a little feedback from guys,
appreciating the problem, and maybe indicating that there are efforts going
 
B

Brian Teutsch [MSFT]

We appreciate the problem and we are concerned about performance. Glad to
see the suggestions worked out for you, there's nothing better we can
suggest ourselves.

Brian
 
G

G. Tarazi

Hi



The only differences in performance that I have noticed by now (between the
managed code and the script) were in the event handlers, I guess it's a bug
in InfoPath, but otherwise, my managed code is working way faster than the
Java Script, of course I am still limited with the speed of the DOM, but so
do the java script.



A large form today (one of my forms) takes from 3 to 5 seconds to fully open
(from the time it's clicked on the web site, to the time its opened on the
end user machine, and that includes the automated xml generation in the
background that is comming from SQL Server, etc).



You just need to be a bit more careful with the code, and Microsoft must
publish something about the event handlers, and their possible workarounds,
to make a bit easier for the other developers.



Another issue that you may have with InfoPath, and may slow down the
performance, is an improper combination use of Conditional Formatting, and
Rules, I had one of these problems in a from (a form with a 2000+ controls)
and this improper combination was cussing the form about 20 seconds delay.



I was thinking that the conditional formatting was slow, but after comparing
that form with another form, that was much complex than the original one, we
found out that the conditional formatting actually is fast, its just simple
xsl (its speed depends of the complexity of the form, but it is still
relatively fast).



By today it has been 1 year and one month since I have started developing
applications for InfoPath using C# (I started with the SP1 beta), I did
complain a lot in these newsgroups the past year :) I guess they hate me
for that, the product has a lot of limitations that I don't like, but it is
still the most suitable product for my project.



I hope their next release either uses Avalon instead of XSL/MSHTML.DLL, or
the Microsoft Word/Excel Engine, in the background.



Good luck
 

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