Why FileSystemWatcher doesn't work in Linux container watching Windows volume
Switching to PhysicalFileProvider 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 Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using System;
using System.IO;
namespace fsw_bug_poc
{
class Program
{
private static PhysicalFileProvider _fileProvider;
private static IChangeToken _fileChangeToken;
static void Main(string[] args)
{
_fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "."));
WatchForFileChanges();
Console.ReadKey(false);
}
private static void WatchForFileChanges()
{
_fileChangeToken = _fileProvider.Watch("*.*");
_fileChangeToken.RegisterChangeCallback(Notify, default);
}
private static void Notify(object state)
{
Console.WriteLine("File change detected");
WatchForFileChanges();
}
}
}
FileSystemWatcher locks folder
I've discovered what caused this. There was a second FileSystemWatcher
- on a sub directory of the first - which didn't allow renaming the first.
(I'm still surprised, though. A FileSystemWatcher
should be "invisible".)
Related Topics
Fire and Forget Async Method in ASP.NET MVC
How to Mock the Httpcontext in ASP.NET MVC Using Moq
Stataskscheduler and Sta Thread Message Pumping
Where Is the Application.Doevents() in Wpf
Using Protobuf-Net, I Suddenly Got an Exception About an Unknown Wire-Type
Entity Framework (Ef) Code First Cascade Delete for One-To-Zero-Or-One Relationship
Add New Item in Existing Array in C#.Net
Variable Scope Confusion in C#
Sqlcommand Parameters Add VS. Addwithvalue
How to Change Menu Hover Color
How to Format Datetime Columns in Datagridview
ASP.NET MVC $.Post Call Returning String...Need Help with Format for Jqgrid
How to Serialize a Dictionary as Part of Its Parent Object Using JSON.Net
How to Turn an Int into an Array of Ints of Each Digit
How to Access a Variable from Another Script in Another Gameobject Through Getcomponent