i filewatching a dir for deletion, addition and change. I started with addition. The processing time forces me to have a queue management otherwise i'll skip a lot of files added in the dir. Here is the code : Declaration :
static ConcurrentQueue<string> q = new ConcurrentQueue<string>();
Then in the Form_load :
Task.Factory.StartNew(filesAdded);
the Filewatcher function :
private void fileSystemWatcher1_Created_1(object sender, FileSystemEventArgs e)
{
q.Enqueue(e.FullPath);
}
And then the filesAdded function :
void filesAdded ()
{
bool run = true;
AppDomain.CurrentDomain.DomainUnload += (s, e) =>
{
run = false;
q.Enqueue("stop");
};
while (run)
{
string filename;
if (q.TryDequeue(out filename) && run)
{
Globals.getTags(filename);
Globals.ecritDs(filename, true);
}
}
}
credit goes to Rene here
it's working fine but i'm struggling to find a way to use the same mechanism for modified & deleted files.
private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
{}
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{}
I would like to get the trigger info in the filesAdded function (that obviously needs to be renamed) but i have no idea how to do it since the Enqueue method takes only one parameter. Any help is appreciated !