visual studio shell SelectionEvents OnChange事件丢失问题
来源:互联网 发布:乐乎美女图片 编辑:程序博客网 时间:2024/05/14 18:24
解决办法如下:
http://stackoverflow.com/questions/14165885/add-in-events-are-never-executed
down vote
If you look at applicationObject in the debugger you'll see its a COM object, but the xxxEvents classes are not (If you can't get the code to break on OnConnection, then possibly your addin isn't getting loaded when you debug, check the tools menu)
Events in COM are handled by a separate COM interface (several in this case) in the other direction which the server (VS) calls to fire them.
Although COM objects have a similar typed assembly concept to CLR assemblies they are unmanaged code internally, so cannot hold roots to managed objects.
So although you can hook a delegate to a COM event in a way that looks exactly like a native CLR event, your event is hooked to an RCW (runtime callable wrapper). There is a COM reference from the server to the RCW com interface, but without a CLR root the RCW eventually gets disposed which unloads the com interface, after which you won't sink any events.
I'm not sure but I think this normally works when you consume a single COM object with a direct association to its event interfaces so its maybe due to how the DTE COM interface is structured...
Anyway as others have said you just need any kind of managed reference to the BuildEvents, SelectionEvents and DocumentEvents classes from the app object to fix it. Multiple instances of VS load separate instances of the add in so you could just add a list of static object refs and set them in OnConnect.
Subscription to DTE events doesn't seem to work - Events don't get called
http://msdn.microsoft.com/en-us/library/k639e386.aspx
If you look at applicationObject in the debugger you'll see its a COM object, but the xxxEvents classes are not (If you can't get the code to break on OnConnection, then possibly your addin isn't getting loaded when you debug, check the tools menu)
Events in COM are handled by a separate COM interface (several in this case) in the other direction which the server (VS) calls to fire them.
Although COM objects have a similar typed assembly concept to CLR assemblies they are unmanaged code internally, so cannot hold roots to managed objects.
So although you can hook a delegate to a COM event in a way that looks exactly like a native CLR event, your event is hooked to an RCW (runtime callable wrapper). There is a COM reference from the server to the RCW com interface, but without a CLR root the RCW eventually gets disposed which unloads the com interface, after which you won't sink any events.
I'm not sure but I think this normally works when you consume a single COM object with a direct association to its event interfaces so its maybe due to how the DTE COM interface is structured...
Anyway as others have said you just need any kind of managed reference to the BuildEvents, SelectionEvents and DocumentEvents classes from the app object to fix it. Multiple instances of VS load separate instances of the add in so you could just add a list of static object refs and set them in OnConnect.
Subscription to DTE events doesn't seem to work - Events don't get called
http://msdn.microsoft.com/en-us/library/k639e386.aspx
- visual studio shell SelectionEvents OnChange事件丢失问题
- 解决在Microsoft Visual Studio .NET 2003页面切换按钮等事件丢失的问题
- select的onchange事件问题
- Visual Studio 模板丢失解决方法
- visual studio模板丢失 解决方法
- Visual Studio 2008 Shell
- Visual Studio 2008 Shell
- EasyUI datetimebox 的onchange事件的问题
- EasyUI datetimebox 的onchange事件的问题
- onchange事件
- onchange事件
- onchange 事件
- onChange事件
- Visual Studio 2015中ucrtbased.dll丢失
- Visual Studio 2015中ucrtbased.dll丢失
- Visual Studio 2015中ucrtbased.dll丢失
- Visual Studio 2015中ucrtbased.dll丢失
- onchange事件在失去焦点事件之后发生的问题?
- 使用AOP为类动态添加方法
- SQL Server管理器常见问题
- 一个安装python库的好方法
- ob缓冲
- 模型烘焙后保存mesh数据生成新的预制体
- visual studio shell SelectionEvents OnChange事件丢失问题
- redis 高可用解决方案
- 在软件中常用的“撤销”操作,其本质是“栈”!
- 常用的一些页面操作 js jsp check
- tensorflow笔记 :常用函数说明
- 详解JVM的内存管理机制
- MySQL忘记密码解决
- mybatis foreach collection 用法
- 用PDF编辑器怎样修改PDF文件内容