Home All Groups Group Topic Archive Search About

filesystemwatcher changed vb.net

Author
31 Mar 2005 6:19 AM
marfi95
Hi all,

I have implemented a filesystemwatcher to notify my app when a specific
file has changed.  I have a notifyfilter of LastWrite or Size.
However, just opening the file is triggering this.  Is there a way
around this since I only want to know when changes have been made ?

Mark

Author
31 Mar 2005 11:24 AM
Herfried K. Wagner [MVP]
<marf***@yahoo.com> schrieb:
> I have implemented a filesystemwatcher to notify my app when a specific
> file has changed.  I have a notifyfilter of LastWrite or Size.
> However, just opening the file is triggering this.  Is there a way
> around this since I only want to know when changes have been made ?

Short but complete programs
<URL:http://www.pobox.com/~skeet/csharp/complete.html>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
31 Mar 2005 2:09 PM
marfi95
All I was saying is that just opening the file I am watching is
triggering a change event.  Here is the code:

    Private Sub SetWatcherData()

        watcher.Path = ValidateNetworkFileItemPath

        ' -- set notification for when the validation file is updated
        watcher.NotifyFilter = (NotifyFilters.LastWrite Or
NotifyFilters.Size)
        watcher.Filter = ValidateItemFileName

        ' Add event handlers.
        AddHandler watcher.Changed, AddressOf OnSerializedFileChanged

        ' Begin watching.
        watcher.EnableRaisingEvents = True

    End Sub

Private Sub OnSerializedFileChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
       MsgBox(e.ChangeType & " " & e.FullPath & " " & e.Name)
End Sub

By just opening the file specified in the variable
(ValidateItemFileName), the event is getting triggered.