Hi,
I am trying to use FileSystemWatch er to watch a log file which is
written to via a 3rd party app and display the log in listbox on a
form. The FileSystemWatch seems to work okay but I get the following
error when I try to write to the listbox:
"A first chance exception of type 'System.Argumen tNullException'
occurred in System.Windows. Forms.dll"
being in a different thread but to be honest I haven't really figured
the ins and outs of threading. This was meant to be a nice simple
project to learn from so I'd really appreciate any tips.
My form has a run button which calls the following routine (in a
separate module):
Private mstrPathToWatch As String
Private mstrFileToWatch As String
Private mfswWatchFolder As FileSystemWatch er
Private frm As frmMain
Public Sub StartFileWatch( ByVal frmLogForm As frmMain)
mfswWatchFolder = New FileSystemWatch er
mfswWatchFolder .SynchronizingO bject = frmLogForm.lbxR unLog
'this was just a guess but I don't understand it and it
doesn't seem to help
'Create module level reference to form so can access it from
changed event
frm = frmLogForm
'Specify the path we want to watch
mstrPathToWatch = "C:\Documen ts and Settings\Andrew \My
Documents\TEMP"
mstrFileToWatch = "demo.txt"
mfswWatchFolder .Path = mstrPathToWatch
mfswWatchFolder .Filter = mstrFileToWatch
'Add a list of Filter we want to specify
mfswWatchFolder .NotifyFilter = IO.NotifyFilter s.DirectoryName
mfswWatchFolder .NotifyFilter = mfswWatchFolder .NotifyFilter Or
IO.NotifyFilter s.FileName
mfswWatchFolder .NotifyFilter = mfswWatchFolder .NotifyFilter Or
IO.NotifyFilter s.Attributes
'Add a handler for each event (in this case just file change)
AddHandler mfswWatchFolder .Changed, AddressOf FileHasChanged
'Set this property to true to start watching
mfswWatchFolder .EnableRaisingE vents = True
End Sub
The 'FileHasChanged ' event created above reads the log file
(successfully) and then calls a sub back on the form which writes the
array to the listbox.
Thanks a lot!
Andrew
I am trying to use FileSystemWatch er to watch a log file which is
written to via a 3rd party app and display the log in listbox on a
form. The FileSystemWatch seems to work okay but I get the following
error when I try to write to the listbox:
"A first chance exception of type 'System.Argumen tNullException'
occurred in System.Windows. Forms.dll"
>From my search so far it seems this may be to do with the watcher
the ins and outs of threading. This was meant to be a nice simple
project to learn from so I'd really appreciate any tips.
My form has a run button which calls the following routine (in a
separate module):
Private mstrPathToWatch As String
Private mstrFileToWatch As String
Private mfswWatchFolder As FileSystemWatch er
Private frm As frmMain
Public Sub StartFileWatch( ByVal frmLogForm As frmMain)
mfswWatchFolder = New FileSystemWatch er
mfswWatchFolder .SynchronizingO bject = frmLogForm.lbxR unLog
'this was just a guess but I don't understand it and it
doesn't seem to help
'Create module level reference to form so can access it from
changed event
frm = frmLogForm
'Specify the path we want to watch
mstrPathToWatch = "C:\Documen ts and Settings\Andrew \My
Documents\TEMP"
mstrFileToWatch = "demo.txt"
mfswWatchFolder .Path = mstrPathToWatch
mfswWatchFolder .Filter = mstrFileToWatch
'Add a list of Filter we want to specify
mfswWatchFolder .NotifyFilter = IO.NotifyFilter s.DirectoryName
mfswWatchFolder .NotifyFilter = mfswWatchFolder .NotifyFilter Or
IO.NotifyFilter s.FileName
mfswWatchFolder .NotifyFilter = mfswWatchFolder .NotifyFilter Or
IO.NotifyFilter s.Attributes
'Add a handler for each event (in this case just file change)
AddHandler mfswWatchFolder .Changed, AddressOf FileHasChanged
'Set this property to true to start watching
mfswWatchFolder .EnableRaisingE vents = True
End Sub
The 'FileHasChanged ' event created above reads the log file
(successfully) and then calls a sub back on the form which writes the
array to the listbox.
Thanks a lot!
Andrew
Comment