|
-
August 8th, 2011, 11:30 AM
#1
filesystem watcher duplicates events
Hello,
I wrote a simple watcher that monitors a folder for events (files being changed - they are overwritten via ftp) and when this happens displays a message on the console and runs a matlab script.
this is part of the code:
private static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("File: " + e.Name + " " + e.ChangeType);
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "C:\\Program Files\\MATLAB\\R2011a\\bin\\matlab.bat",
Arguments = "-r \"prova=1;file\" ";
}
};
process.Start();
process.WaitForExit();
}
public static void Run()
{
string pathToWatch = "C:\\Documents and Settings\\aa";
string[] args = System.Environment.GetCommandLineArgs();
.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = pathToWatch;
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Changed += new FileSystemEventHandler(OnChanged);
// Begin watching.
watcher.EnableRaisingEvents = true;
}
It works all fine besides the fact that every time a file is changed, it displays it twice on the console and runs matlab twice. There are ways to avoid this, of course, but I was wondering why this happens?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|