ドッキングコンテナ内のプログラムは、FileSystemWatcherを使用してローカルフォルダを監視します。Docker内のFileSystemWatcherはローカルディレクトリの変更を認識しません
ドッカー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
実行中にDocker Execを使用してコンテナを調べました。受信トレイと送信トレイのディレクトリとその中にあるファイルを見ることができます。しかし、新しいファイルを受信トレイに投げると、FileSystemWatcherイベントは発生しません。ドッカーコンテナを使用しないとうまく動作しないので、コードに何も問題はありません。
ディレクターの取り付けに何か他に必要なことはありますか?または、FileSystemWatcherはコンテナ内でも使用できますか?
さて、要求されたとして、ここではプログラムがあります:
私のローカルドライブ上の受信トレイフォルダがコンテナ内の受信フォルダに関連付けられています:
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);
}
}
}
}
コードを見なくても、自分が行っていることや正しく行っていないことを判断することは非常に困難です。 – MethodMan