Given the program:
using System;
using System.IO;
namespace fsw_bug_poc
{
class Program
{
private static
Switching to PhysicalFileProvider.Watch did the job. It seems to be a more portable implementation for file system watching strategies.
The current implementation of PhysicalFileProvider
supports the DOTNET_USE_POLLING_FILE_WATCHER
environment variable. I couldn't find any reference of it in FileSystemWatcher
implementation.
using System;
using System.IO;
namespace fsw_bug_poc
{
class Program
{
private static PhysicalFileProvider _fileProvider;
static void Main(string[] args)
{
_fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Watched"));
WatchForFileChanges();
Console.ReadKey(false);
}
private void WatchForFileChanges()
{
_fileChangeToken = _fileProvider.Watch("*.*");
_fileChangeToken.RegisterChangeCallback(Notify, default);
}
private void Notify(object state)
{
Console.WriteLine("File change detected");
WatchForFileChanges();
}
}
}