I'm trying to use the solution found here [Create multiple instances of the same FileSystemWatcher to make FileSystemWatchers on the fly but the Watcher_Created event doesn't seem to be triggered. Any thoughts as to what I am doing wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Type Enter to exit:::");
StartWatchers();
Console.ReadLine();
}
public static void StartWatchers()
{
string[] ArrayPaths = new string[2];
List<FileSystemWatcher> watchers = new List<FileSystemWatcher>();
ArrayPaths[0] = @"\\WifeyPC\c$\User\Wifey\Desktop";
ArrayPaths[1] = @"\\HubbyPC\c$\Users\Hubby\Desktop";
int i = 0;
foreach (String String in ArrayPaths)
{
watchers.Add(MyWatcherFatory(ArrayPaths[i]));
i++;
}
foreach (FileSystemWatcher watcher in watchers)
{
watcher.EnableRaisingEvents = true; ;
Console.WriteLine("Watching this folder {0}", watcher.Path);
i++;
}
}
FileSystemWatcher MyWatcherFatory(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher(path);
watcher.Changed += Watcher_Created;
watcher.Path = path;
watcher.Filter = "*.txt";
watcher.IncludeSubdirectories = true;
return watcher;
}
private void Watcher_Created(object sender, FileSystemEventArgs e)
{
System.Threading.Thread.Sleep(1000);
FileInfo fileInfo = new FileInfo(e.FullPath);
Console.WriteLine("File Created!! :: {0}", e.FullPath);
}
}
}