Search code examples
c#.netcominteropcom-interop

.NET / COM events interoperability


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?


Solution

  • Solved by using custom Advise/Unadvise callbakcs.