deleting an filewatcher object that was created in code

  • Thread starter Thread starter Aussie Rules
  • Start date Start date
A

Aussie Rules

Hi

I create a number of filewatchers in my code. I have a need to delete some
of the file watchers, but can not figure out how to do this without stopping
the application and restarting.

To create the filewatcher I have this code.... There doesn't seem to be a
name or index for the filewatch so how do I delete one?

Dim watcher As New FileSystemWatcher()
watcher.Path = strPath
watcher.NotifyFilter = (NotifyFilters.LastAccess Or
NotifyFilters.LastWrite Or NotifyFilters.FileName Or
NotifyFilters.DirectoryName)
watcher.Filter = strFilter
 
Aussie,

Simple answer, you cannot change an application without stopping it.

After building you are installing in fact a new application.

Cor
 
Hi

I create a number of filewatchers in my code. I have a need to delete some
of the file watchers, but can not figure out how to do this without stopping
the application and restarting.

To create the filewatcher I have this code.... There doesn't seem to be a
name or index for the filewatch so how do I delete one?

Dim watcher As New FileSystemWatcher()
watcher.Path = strPath
watcher.NotifyFilter = (NotifyFilters.LastAccess Or
NotifyFilters.LastWrite Or NotifyFilters.FileName Or
NotifyFilters.DirectoryName)
watcher.Filter = strFilter

You would need to remember the reference to the object, probably in a
form property, and then probably call its Dispose method to make it
stop watching.
 
Back
Top