My program inside a docker container uses FileSystemWatcher to monitor a local folder. I mounted the directory with:
docker run -v /c/Users/Support/Desktop/inbox:/Users/Support/Desktop/inbox -v /c/Users/Support/Desktop/outbox:/Users/Support/Desktop/outbox -it --name workbeanRun workbean
I used Docker Exec to look into the container while it was running. It can see the inbox and outbox directories along with any files that are in it. However, when I throw a new file into the inbox, the FileSystemWatcher event does not fire. There's nothing wrong with the code because if I don't use a docker container, it runs fine.
Is there anything else I need to do in mounting the directores? Or is FileSystemWatcher even possible inside a container?
Okay, as requested, here's the program:
using System;
using System.IO;
namespace workbean
{
class Program
{
FileSystemWatcher watcher = new FileSystemWatcher();
static string sourceDir = "/Users/Support/Desktop/inbox";
static string destDir = "/Users/Support/Desktop/outbox";
static void Main(string[] args)
{
Console.WriteLine("Testing...");
Program p = new Program();
while (true) { }
}
public Program()
{
watcher.Path = sourceDir;
watcher.Filter = "*.*";
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
static void OnCreated(object source, FileSystemEventArgs e)
{
string[] files = Directory.GetFiles(sourceDir);
foreach (var item in files)
{
string destDir2 = destDir + "/" + Path.GetFileName(item);
File.Move(item, destDir2);
}
}
}
}