Reputation: 551
For some reason I can not remove an event handler from the FileSystemWatcher.
This is what I have
void Start()
{
ivFileSystemWatcher = new FileSystemWatcher();
ivFileSystemWatcher.Changed +=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
}
void Stop()
{
ivFileSystemWatcher.Changed -=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
ivFileSystemWatcher.Dispose();
}
When I call start I start receiving the change events, but when I call stop I am expecting the events to stop but they are still being raised.
Upvotes: 5
Views: 14608
Reputation: 300499
Have you tried setting EnableRaisingEvents
to false
:
void Stop()
{
ivFileSystemWatcher.EnableRaisingEvents = false;
ivFileSystemWatcher.Changed -=
new FileSystemEventHandler(ivFileSystemWatcher_Changed);
ivFileSystemWatcher.Dispose();
}
Without seeing the rest of your code, I'm not convinced that's the best place for the Dispose()
...
Upvotes: 11