2
運行VS 2012.我創建了一個加載項。我想處理OnEnterBreakMode事件。 Exec方法被調用。我試着返回處理=真/假。該處理程序從不被調用。我嘗試了DTE和DTE2的一些變體。我進入工具菜單>單擊「MyAddIn1」,並調用Exec方法。我證實了這件事是有約束力的。我不知道加載項的生命週期如何工作。OnEnterBreakMode不會觸發
StartEvents
不是一個覆蓋,它沒有連接到任何東西。我覺得奇怪......
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName == "MyAddin1.Connect.MyAddin1")
{
//handled = true;
// Place the following code in the Exec method of the add-in:
EnvDTE.DebuggerEvents debugEvents = _applicationObject.Events.DebuggerEvents;
debugEvents.OnEnterBreakMode += new _dispDebuggerEvents_OnEnterBreakModeEventHandler(Connect.BreakHandler);
return;
}
}
}
private DTE _applicationObject;
private AddIn _addInInstance;
// Place the following Event handler code in the add-in:
// Needed to activate event handlers in Connect.Exec.
public static void StartEvents(DTE dte)
{
Console.WriteLine("Events are attached.");
}
// OnEnterBreakMode Event.
public static void BreakHandler(dbgEventReason reason, ref dbgExecutionAction execAction)
{
Console.WriteLine("Debugger enters break mode. " + "Reason: " + reason.ToString());
}