DTEEvents.OnStartupComplete事件不适用于VSPackage(VSSDK2010) [英] DTEEvents.OnStartupComplete event not working for VSPackage (VSSDK2010)
本文介绍了DTEEvents.OnStartupComplete事件不适用于VSPackage(VSSDK2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Package构造函数中,我为OnStartupComplete事件添加了事件处理程序.但是,当我运行代码时,不会调用事件处理程序.我在做什么错了?
In the Package constructor I added the event handler for OnStartupComplete event. But when I run the code, the the event handler is not called. What am I doing wrong?
推荐答案
VS中存在一个错误,除非您保留对它的明确引用,否则它会(使用事件处理程序)回收DTEEvents
对象.您需要这样的东西:
There's a bug in VS that recycles the DTEEvents
object (with your event handlers) unless you keep an explicit reference to it. You need something like this:
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string)]
class MyPackage : Package
{
DTEEvents _EventsObj;
protected override void Initialize()
{
var dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
_EventsObj = dte.Events.DTEEvents;
_EventsObj.OnStartupComplete += OnStartupComplete;
}
void OnStartupComplete()
{
}
}
这篇关于DTEEvents.OnStartupComplete事件不适用于VSPackage(VSSDK2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文