|
Subject:
|
attach FileWatcher eventhandlers dynamically
|
|
Posted By:
|
neethling
|
Post Date:
|
1/11/2006 9:17:33 AM
|
I'm trying to attach FileWatcher eventhandlers dynamically to a Windows Service. However the code cracks with the following message:
Exception: {"Object does not match target type." }
Code: f = a.GetType("System.IO.FileSystemWatcher", true, true); fw = Activator.CreateInstance(f);
//set the eventhandler ei = f.GetEvent("Changed"); ei.AddEventHandler(f, new FileSystemEventHandler(FileListener.OnChanged)); ei = fw.GetType().GetEvent("Created"); ei.AddEventHandler(fw, new FileSystemEventHandler(FileListener.OnChanged)); ei = fw.GetType().GetEvent("Deleted"); ei.AddEventHandler(fw, new FileSystemEventHandler(FileListener.OnChanged)); ei = fw.GetType().GetEvent("Renamed"); ei.AddEventHandler(fw, new RenamedEventHandler(FileListener.OnRenamed));
Any suggestions?
|
|