
Untitled
By: a guest on
May 28th, 2012 | syntax:
None | size: 0.92 KB | hits: 15 | expires: Never
Using multiple FileSystemWatchers
private static FileSystemWatcher watcherTxt;
private static FileSystemWatcher watcherXml;
static void Main(string[] args)
{
String dir = @"C:temp";
watcherTxt = new FileSystemWatcher();
watcherTxt.Path = dir;
watcherTxt.Filter = "*.txt";
watcherTxt.EnableRaisingEvents = true;
watcherTxt.Created += new FileSystemEventHandler(onCreatedFile);
watcherXml = new FileSystemWatcher();
watcherXml.Path = dir;
watcherXml.Filter = "*.xml";
watcherXml.EnableRaisingEvents = true;
watcherXml.Created += new FileSystemEventHandler(onCreatedFile);
Console.ReadLine();
}
private static void onCreatedFile(object sender, FileSystemEventArgs e)
{
if (watcherTxt == sender)
{
Console.WriteLine("Text Watcher Detected: " + e.FullPath);
}
if (watcherXml == sender)
{
Console.WriteLine("XML Watcher Detected: " + e.FullPath);
}
}