// Note that this method can be called from a thread other than the test main thread. public int HandleCallbackEvent(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent) { if (pEvent is IDebugBreakpointEvent2 || pEvent is IDebugBreakEvent2 || pEvent is IDebugStepCompleteEvent2) { _queue.Push( _programStoppedJobFactory.Create(pEngine, pEvent, _debugSessionContext, pThread)); } else if (pEvent is IDebugProgramDestroyEvent2) { _queue.Push( _programTerminatedJobFactory.Create(pEngine, pEvent, _debugSessionContext)); } var pProgram3 = pProgram as IDebugProgram3; if (pProgram3 == null) { // TODO: Ensure program can be cast to IDebugProgram3 without // throwing across the COM/interop boundary. throw new NotSupportedException( "'pProgram' must be castable to type " + $"{nameof(IDebugProgram3)} but is of type {pProgram.GetType()}"); } _queue.Push(_broadcastDebugEventJobFactory.Create(() => { DebugEventHandler handler = DebugEvent; handler?.Invoke(new DebugEventArgs { DebugEngine = pEngine, Process = pProcess, Program = pProgram3, Thread = pThread, Event = pEvent }); }, pEvent)); return(VSConstants.S_OK); }