DTE2 events don't fire

后端 未结 2 1977
天命终不由人
天命终不由人 2021-01-04 18:57

While trying to develop my first VS Addin, I am having issues in firing DTE2 events.

Basically, the DocumentOpened and LineChanged events don\'t fire for some reason

相关标签:
2条回答
  • 2021-01-04 19:32

    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

    0 讨论(0)
  • 2021-01-04 19:35

    You need to save the DocumentEvents class. I think they will be disposed 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);
    }
    
    0 讨论(0)
提交回复
热议问题