Background Infomation: I am using FileSystemWatcher class implemented in a service to monitor changes in the files. Heres the section of coding that throws an Argument Exception (Path is not a legal form) when the onCreate event is triggered.
FileMonitor.CS
public partial class FileMonitor:ServiceBase
{
public FileSystemWatcher Watcher = new FileSystemWatcher();
Private void FileWatcher()
{
FileActionHandler ActionHandler = new FileActionHandler();
Watcher.Created += new FileSystemEventHandler(ActionHandler.onCreate);
Watcher.Deleted += new FileSystemEventHandler(ActionHandler.onDelete);
Watcher.Renamed += new RenamedEventHandler(ActionHandler.onRenamed);
Watcher.EnableRaisingEvents = true;
}
}
FileActionHandler.CS
class FileActionHandler
{
FileMonitor FileMon = new FileMonitor();
public void onCreate/onRename/onDelete(object source, FileSystemEventArgs e)
{
try
{
FileMon.Watcher.EnableRaisingEvents = false;
}
catch
{
/* Exception Code */
}
finally
{
FileMon.Watcher.EnableRaisingEvents = true;
}
}
}
Question: Can anyone advice me on why is the exception being thrown and how I can go about resolving it ?