1414
1515using System ;
1616using System . Collections . Generic ;
17+ using System . Diagnostics ;
1718using DebuggerApi ;
18- using Microsoft . VisualStudio . Debugger . Interop ;
1919using Microsoft . VisualStudio ;
20- using System . Diagnostics ;
20+ using Microsoft . VisualStudio . Debugger . Interop ;
2121using YetiVSI . DebugEngine . Exit ;
22- using Microsoft . VisualStudio . Threading ;
23- using System . Threading . Tasks ;
2422
2523namespace YetiVSI . DebugEngine
2624{
@@ -124,26 +122,18 @@ public class DebugEngineHandler : IDebugEngineHandler
124122 {
125123 public class Factory : IDebugEngineHandlerFactory
126124 {
127- readonly JoinableTaskContext _taskContext ;
128-
129- public Factory ( JoinableTaskContext taskContext )
125+ public IDebugEngineHandler Create (
126+ IDebugEngine2 debugEngine , IDebugEventCallback2 eventCallback )
130127 {
131- _taskContext = taskContext ;
128+ return new DebugEngineHandler ( debugEngine , eventCallback ) ;
132129 }
133-
134- public IDebugEngineHandler Create ( IDebugEngine2 debugEngine ,
135- IDebugEventCallback2 eventCallback ) =>
136- new DebugEngineHandler ( _taskContext , debugEngine , eventCallback ) ;
137130 }
138131
139- readonly JoinableTaskContext _taskContext ;
140132 readonly IDebugEngine2 _debugEngine ;
141133 readonly IDebugEventCallback2 _eventCallback ;
142134
143- public DebugEngineHandler ( JoinableTaskContext taskContext , IDebugEngine2 debugEngine ,
144- IDebugEventCallback2 eventCallback )
135+ public DebugEngineHandler ( IDebugEngine2 debugEngine , IDebugEventCallback2 eventCallback )
145136 {
146- _taskContext = taskContext ;
147137 _debugEngine = debugEngine ;
148138 _eventCallback = eventCallback ;
149139 }
@@ -155,30 +145,27 @@ public DebugEngineHandler(JoinableTaskContext taskContext, IDebugEngine2 debugEn
155145 // https://docs.microsoft.com/en-us/visualstudio/extensibility/debugger/supported-event-types
156146 public int SendEvent ( IGgpDebugEvent evnt , IGgpDebugProgram program , IDebugThread2 thread )
157147 {
158- return _taskContext . Factory . Run ( async ( ) =>
159- {
160- return await SendEventAsync ( evnt , program , thread ) ;
161- } ) ;
162- }
163-
164- public int SendEvent ( IGgpDebugEvent evnt , IGgpDebugProgram program ,
165- RemoteThread thread ) => SendEvent ( evnt , program ,
166- program . GetDebugThread ( thread ) ) ;
167-
168- async Task < int > SendEventAsync ( IGgpDebugEvent evnt , IGgpDebugProgram program ,
169- IDebugThread2 thread )
170- {
171- await _taskContext . Factory . SwitchToMainThreadAsync ( ) ;
172148
173- if ( ( ( IDebugEvent2 ) evnt ) . GetAttributes ( out uint attributes ) != VSConstants . S_OK )
149+ if ( evnt . GetAttributes ( out uint attributes ) != VSConstants . S_OK )
174150 {
175151 Trace . WriteLine ( $ "Could not get event attributes of event ({ evnt } )") ;
176152 return VSConstants . E_FAIL ;
177153 }
178154
179155 Guid eventId = evnt . EventId ;
180- return _eventCallback . Event ( _debugEngine , null , program , thread , evnt , ref eventId ,
181- attributes ) ;
156+
157+ #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
158+ // IDebugEventCallback2.Send doesn't actually require to be called on the main thread.
159+ var ret = _eventCallback . Event (
160+ _debugEngine , null , program , thread , evnt , ref eventId , attributes ) ;
161+ #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
162+
163+ return ret ;
164+ }
165+
166+ public int SendEvent ( IGgpDebugEvent evnt , IGgpDebugProgram program , RemoteThread thread )
167+ {
168+ return SendEvent ( evnt , program , program . GetDebugThread ( thread ) ) ;
182169 }
183170 }
184171}
0 commit comments