简体   繁体   English

.NET / COM事件互操作性

[英].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. 我有一个由TlbImp.exe生成的互操作程序集,生成的类事件严重,性能非常重要。

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: 但是有一个问题,这些事件似乎是以某种方式注册/注销/调用的,即使是空的事件处理程序也都被计入。给定一组1..N个事件,当您将处理程序注册到事件3时,它看起来像这个:

{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? 所以问题是,是否有更好的方法来处理.NET中的COM事件? Any tool or something or do I have to rewrite the event code of the interop assembly from scratch? 任何工具或其他工具,还是我必须从头开始重写互操作程序集的事件代码?

Why not just allow .NET to build the interop by doing a Using statement? 为什么不只允许.NET通过执行Using语句来构建互操作?

No events should be invoked unless you explicitly set them. 除非您明确设置事件,否则不应调用任何事件。

Example: 例:

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

As you can see the above example sets many events. 如您所见,上面的示例设置了许多事件。

通过使用自定义解决Advise / Unadvise callbakcs。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM