views:

227

answers:

2

I have an interop assembly generated by TlbImp.exe, the generated classes are heavily evented and the performance is very important.

But there's a problem, the events seem to be registered/unregistered/invoked in such a manner that even empty event handlers are counted in. Given a set of 1..N events, when you register a handler to an event 3 it looks like this:

{dummy1, dummy2, eventHandler3, dummy4 ... dummyN}

Which generates a large overhead when there's a lot of events that get raised very often.

So the question is, is there a better way how to work with COM events in .NET? Any tool or something or do I have to rewrite the event code of the interop assembly from scratch?

A: 

Why not just allow .NET to build the interop by doing a Using statement?

No events should be invoked unless you explicitly set them.

Example:

http://code.msdn.microsoft.com/SEHE

As you can see the above example sets many events.

That calls TlbImp.exe for you. And that way is very slow since it creates SinkHelper for each type that defines events.
arul
A: 

Solved by using custom Advise/Unadvise callbakcs.

arul