@@ -50,12 +50,8 @@ public RemoteSync(string host, string username, string password,
5050
5151 DoneInitialSync = InitialSync ( _localRootDirectory , _remoteRootDirectory ) ;
5252
53- //Once the initial sync is done, we can start watching the file system for changes
54-
55- DoneInitialSync . ContinueWith ( ( tmp ) =>
56- {
57- _director . AddCallback ( searchPattern , ( args ) => Fsw_Changed ( null , args ) ) ;
58- } ) ;
53+ // Register callbacks immediately; handler will ignore events until initial sync completes.
54+ _director . AddCallback ( searchPattern , ( args ) => Fsw_Changed ( null , args ) ) ;
5955 }
6056
6157 public RemoteSync ( string host , string username , string password ,
@@ -76,10 +72,8 @@ public RemoteSync(string host, string username, string password,
7672
7773 DoneInitialSync = initialSyncTask ;
7874
79- DoneInitialSync . ContinueWith ( ( tmp ) =>
80- {
81- _director . AddCallback ( searchPattern , ( args ) => Fsw_Changed ( null , args ) ) ;
82- } ) ;
75+ // Register callbacks immediately; handler will ignore events until initial sync completes.
76+ _director . AddCallback ( searchPattern , ( args ) => Fsw_Changed ( null , args ) ) ;
8377 }
8478
8579 public static async Task RunSharedInitialSyncAsync (
@@ -433,6 +427,9 @@ private async void Fsw_Changed(object? sender, FileSystemEventArgs arg)
433427 {
434428 try
435429 {
430+ if ( ! DoneInitialSync . IsCompleted )
431+ return ;
432+
436433 if ( arg . ChangeType == WatcherChangeTypes . Changed || arg . ChangeType == WatcherChangeTypes . Created
437434 || arg . ChangeType == WatcherChangeTypes . Renamed )
438435 {
0 commit comments