@@ -185,7 +185,7 @@ private static async Task MainTask()
185185 foreach ( var fileSystemInfo in new DirectoryInfo ( Global . SyncPath )
186186 . GetFileSystemInfos ( "*." + Global . WatchedCodeExtension , SearchOption . AllDirectories ) )
187187 {
188- await consoleWatch . OnAddedAsync
188+ await ConsoleWatch . OnAddedAsync
189189 (
190190 new DummyFileSystemEvent ( fileSystemInfo ) ,
191191 new CancellationToken ( )
@@ -195,7 +195,7 @@ await consoleWatch.OnAddedAsync
195195 foreach ( var fileSystemInfo in new DirectoryInfo ( Global . SyncPath )
196196 . GetFileSystemInfos ( "*." + Global . WatchedResXExtension , SearchOption . AllDirectories ) )
197197 {
198- await consoleWatch . OnAddedAsync
198+ await ConsoleWatch . OnAddedAsync
199199 (
200200 new DummyFileSystemEvent ( fileSystemInfo ) ,
201201 new CancellationToken ( )
@@ -207,7 +207,7 @@ await consoleWatch.OnAddedAsync
207207 foreach ( var fileSystemInfo in new DirectoryInfo ( Global . AsyncPath )
208208 . GetFileSystemInfos ( "*." + Global . WatchedCodeExtension , SearchOption . AllDirectories ) )
209209 {
210- await consoleWatch . OnAddedAsync
210+ await ConsoleWatch . OnAddedAsync
211211 (
212212 new DummyFileSystemEvent ( fileSystemInfo ) ,
213213 new CancellationToken ( )
@@ -217,7 +217,7 @@ await consoleWatch.OnAddedAsync
217217 foreach ( var fileSystemInfo in new DirectoryInfo ( Global . AsyncPath )
218218 . GetFileSystemInfos ( "*." + Global . WatchedResXExtension , SearchOption . AllDirectories ) )
219219 {
220- await consoleWatch . OnAddedAsync
220+ await ConsoleWatch . OnAddedAsync
221221 (
222222 new DummyFileSystemEvent ( fileSystemInfo ) ,
223223 new CancellationToken ( )
@@ -236,8 +236,14 @@ await consoleWatch.OnAddedAsync
236236 // listen for the Ctrl+C
237237 WaitForCtrlC ( ) ;
238238
239+ Console . WriteLine ( "Stopping..." ) ;
240+
239241 // stop everything.
240242 watch . Stop ( ) ;
243+
244+ Console . WriteLine ( "Exiting..." ) ;
245+
246+ GC . KeepAlive ( consoleWatch ) ;
241247 }
242248 }
243249 catch ( Exception ex )
@@ -310,7 +316,7 @@ internal class ConsoleWatch
310316 /// We need a static lock so it is shared by all.
311317 /// </summary>
312318 private static readonly object Lock = new object ( ) ;
313- private static readonly AsyncLock AsyncLock = new AsyncLock ( ) ; //TODO: use this
319+ // private static readonly AsyncLock AsyncLock = new AsyncLock(); //TODO: use this
314320
315321#pragma warning disable S2223 //Warning S2223 Change the visibility of 'DoingInitialSync' or make it 'const' or 'readonly'.
316322 public static bool DoingInitialSync = false ;
@@ -545,7 +551,7 @@ private static bool IsWatchedFile(string fullName)
545551 } //private bool IsWatchedFile(string fullName, Context context)
546552
547553#pragma warning disable AsyncFixer01
548- private async Task OnRenamedAsync ( IRenamedFileSystemEvent rfse , CancellationToken token )
554+ private static async Task OnRenamedAsync ( IRenamedFileSystemEvent rfse , CancellationToken token )
549555 {
550556 var context = new Context ( rfse , token ) ;
551557
@@ -579,7 +585,7 @@ private async Task OnRenamedAsync(IRenamedFileSystemEvent rfse, CancellationToke
579585 }
580586 }
581587
582- private async Task OnRemovedAsync ( IFileSystemEvent fse , CancellationToken token )
588+ private static async Task OnRemovedAsync ( IFileSystemEvent fse , CancellationToken token )
583589 {
584590 var context = new Context ( fse , token ) ;
585591
@@ -605,7 +611,7 @@ private async Task OnRemovedAsync(IFileSystemEvent fse, CancellationToken token)
605611 }
606612 }
607613
608- public async Task OnAddedAsync ( IFileSystemEvent fse , CancellationToken token )
614+ public static async Task OnAddedAsync ( IFileSystemEvent fse , CancellationToken token )
609615 {
610616 var context = new Context ( fse , token ) ;
611617
@@ -631,7 +637,7 @@ public async Task OnAddedAsync(IFileSystemEvent fse, CancellationToken token)
631637 }
632638 }
633639
634- private async Task OnTouchedAsync ( IFileSystemEvent fse , CancellationToken token )
640+ private static async Task OnTouchedAsync ( IFileSystemEvent fse , CancellationToken token )
635641 {
636642 var context = new Context ( fse , token ) ;
637643
0 commit comments