Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Damianoux opened this issue Apr 5, 2024 · 0 comments

Comments

@Damianoux
Copy link

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);
        }
    }
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant