FileWatcherEx icon indicating copy to clipboard operation
FileWatcherEx copied to clipboard

Copying Large file under watched path cause events Created and Changed to fire

Open Damianoux opened this issue 10 months ago • 0 comments

Start FileSystemWatcherEx, then try to copy a very large file in the watched path. Result: Two events are fired, "Created" on start copying and "Changed" on end copying Expected: Only Created Event shoul have been fired at the end of copy when file is ready to be processed, dame as for small files. Here is the test code:

`using System; using System.IO; using FileWatcherEx;

namespace MyNamespace { class MyClassCS { static void Main() { Environment.SetEnvironmentVariable("DOTNET_USE_POLLING_FILE_WATCHER", "1");

        using var watcher = new FileSystemWatcherEx(@"\\my\path");

        watcher.NotifyFilter = NotifyFilters.Attributes
                             | NotifyFilters.CreationTime
                             | NotifyFilters.DirectoryName
                             | NotifyFilters.FileName
                             | NotifyFilters.LastAccess
                             | NotifyFilters.LastWrite
                             | NotifyFilters.Security
                             | NotifyFilters.Size;

        // event handlers
        watcher.OnRenamed += FWOnChanged;
        watcher.OnCreated += FWOnCreated;
        watcher.OnDeleted += FWOnDeleted;
        watcher.OnChanged += FWOnChanged;
        watcher.OnError += FWOnError;

        watcher.Filter = "*.*";
        watcher.IncludeSubdirectories = true;

        // thread-safe for event handlers
       // watcher.SynchronizingObject = this;

        // start watching
        watcher.Start();


        Console.WriteLine("Press enter to exit.");
        Console.ReadLine();
    }

    private static void FWOnChanged(object? sender, FileChangedEvent e)
    {

        Console.WriteLine($"Changed: {e.FullPath}");
    }

    private static void FWOnCreated(object? sender, FileChangedEvent e)
    {
        string value = $"Created: {e.FullPath}";
        Console.WriteLine(value);
    }

    private static void FWOnDeleted(object? sender, FileChangedEvent e) =>
        Console.WriteLine($"Deleted: {e.FullPath}");

    private static void FWOnRenamed(object? sender, RenamedEventArgs e)
    {
        Console.WriteLine($"Renamed:");
        Console.WriteLine($"    Old: {e.OldFullPath}");
        Console.WriteLine($"    New: {e.FullPath}");
    }

    private static void FWOnError(object? sender, ErrorEventArgs e) =>
        PrintException(e.GetException());

    private static void PrintException(Exception? ex)
    {
        if (ex != null)
        {
            Console.WriteLine($"Message: {ex.Message}");
            Console.WriteLine("Stacktrace:");
            Console.WriteLine(ex.StackTrace);
            Console.WriteLine();
            PrintException(ex.InnerException);
        }
    }
}

}`

Damianoux avatar Apr 05 '24 18:04 Damianoux