DTE2 events don't fire

拥有回忆 提交于 2019-11-30 18:32:12
ptomasroos

You need to save the DocumentEvents class. I think they will be desposed or garbage collected else.

In my case.

private SolutionEvents solutionEvents;

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    Globals.DTE = (DTE2)application;
    Globals.Addin = (AddIn)addInInst;

    solutionEvents = Globals.DTE.Events.SolutionEvents;
    solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
    solutionEvents.BeforeClosing += new _dispSolutionEvents_BeforeClosingEventHandler(SolutionEvents_BeforeClosing);
}

I found a different solution to this problem.

I was boxing and unboxing my DTE object before doing my event subscriptions. This ulitmately proved the culprit for me. While this wasn't your issue, it could help others who have similar issues; and is good to know so that you don't make the same mistakes I did which took an extreme amount of time to resolve.

See here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/eb1e8fd1-32ad-498c-98e9-25ee3da71004

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!