@@ -192,18 +192,21 @@ private void OnChanged(object sender, FileSystemEventArgs args)
192192 if ( ! String . IsNullOrEmpty ( args . FullPath ) && ! String . IsNullOrWhiteSpace ( args . Name ) )
193193 {
194194 string directory = args . FullPath . Replace ( args . Name , "" ) . TrimEnd ( '/' , '\\ ' ) ;
195-
195+
196196 if ( _watchers . TryGetValue ( directory , out WatchLocation watchLocation ) )
197197 {
198- try
198+ if ( Monitor . TryEnter ( watchLocation , TimeSpan . FromSeconds ( 10 ) ) )
199199 {
200- if ( Monitor . TryEnter ( watchLocation , TimeSpan . FromSeconds ( 10 ) ) )
200+ try
201201 {
202202 string saveDirectory = Path . Combine ( _config . BackupsDirectory , watchLocation . SaveGameId . ToString ( ) ) ;
203203 TakeScreenshot ( saveDirectory , watchLocation . GameDirectory ) ;
204204 }
205+ finally
206+ {
207+ Monitor . Exit ( watchLocation ) ;
208+ }
205209 }
206- catch { }
207210 }
208211 }
209212 }
@@ -302,13 +305,24 @@ private void TakeLinuxScreenshot(string saveDirectory)
302305 } ;
303306
304307 Process process = Process . Start ( flameshotStartInfo ) ;
305- process . WaitForExit ( 5000 ) ;
306- process . Close ( ) ;
307308
308- if ( ! File . Exists ( savePath ) )
309+ if ( process . WaitForExit ( 10000 ) )
310+ {
311+ process . Close ( ) ;
312+
313+ Thread . Sleep ( 100 ) ;
314+
315+ if ( ! File . Exists ( savePath ) )
316+ {
317+ _loggingService . LogInfo ( $ "{ nameof ( ScreenshotService ) } >{ nameof ( TakeLinuxScreenshot ) } - Screenshot may have failed") ;
318+ _loggingService . LogInfo ( $ "{ nameof ( ScreenshotService ) } >{ nameof ( TakeLinuxScreenshot ) } - { _flameshotCommand } { arguments } ") ;
319+ }
320+ }
321+ else
309322 {
310- _loggingService . LogInfo ( $ "{ nameof ( ScreenshotService ) } >{ nameof ( TakeLinuxScreenshot ) } - Screenshot may have failed") ;
311- _loggingService . LogInfo ( $ "{ nameof ( ScreenshotService ) } >{ nameof ( TakeLinuxScreenshot ) } - { _flameshotCommand } { arguments } ") ;
323+ _loggingService . LogInfo ( $ "{ nameof ( ScreenshotService ) } >{ nameof ( TakeLinuxScreenshot ) } - Flameshot process timed out, killing it") ;
324+ process . Kill ( ) ;
325+ process . Close ( ) ;
312326 }
313327 }
314328 else
0 commit comments