1111using System ;
1212using System . ComponentModel ;
1313using System . ComponentModel . Composition ;
14+ using System . Diagnostics ;
15+ using System . IO ;
16+ using System . Runtime . CompilerServices ;
1417using System . Windows ;
1518using Process = System . Diagnostics . Process ;
19+ using Task = System . Threading . Tasks . Task ;
1620
1721namespace GtmExtension
1822{
@@ -239,7 +243,7 @@ private void Initialize()
239243 documentEvents = dte . Events . DocumentEvents ;
240244 documentEvents . DocumentSaved += DocumentEvents_DocumentSaved ;
241245 }
242- private void Update ( string path , bool force = false )
246+ private void Update ( string path , bool force = false , [ CallerMemberName ] string caller = null )
243247 {
244248 if ( path == null ) { return ; }
245249
@@ -250,13 +254,26 @@ private void Update(string path, bool force = false)
250254 time - lastUpdate >= updateInterval ||
251255 path != prevPath )
252256 {
253- status = ExecuteForOutput ( gtmExe , $ "record --status \" { path } \" ") ;
254- if ( ! string . IsNullOrWhiteSpace ( status ) )
255- {
256- AppendToWindowTitle ( $ "[GTM: { status } ]") ;
257- }
258-
259257 prevPath = path ;
258+ #if DEBUG
259+ var sw = Stopwatch . StartNew ( ) ;
260+ #endif
261+ Task . Run ( async ( ) =>
262+ {
263+ // This will run in background thread.
264+ status = ExecuteForOutput ( gtmExe , $ "record --status \" { path } \" ") ;
265+
266+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
267+
268+ if ( ! string . IsNullOrWhiteSpace ( status ) )
269+ {
270+ AppendToWindowTitle ( $ "[GTM: { status } ]") ;
271+ }
272+ #if DEBUG
273+ sw . Stop ( ) ;
274+ Debug . WriteLine ( $ "Updated { Path . GetFileName ( path ) } from { caller } in { sw . Elapsed } .") ;
275+ #endif
276+ } ) ;
260277 }
261278 else if ( ! string . IsNullOrWhiteSpace ( status ) )
262279 {
0 commit comments