Hi i'm an event Noob and i'm calling a class from my main module console app
like this. I'm sorry if this is a lot of code to read but i can't see the
error according to my book.
Thanks a LOT.
if there are other noobs here like me feel free to use my code if it's of
any use :)
I've set a breakpoint at doWorkOnChangedFile but notinh happens... i'm
flooding my log like hell.
Dim oFileWatcher As New sysLogIoHandler
oFileWatcher.FileNamePathWithOutEndingSlash = "C:\Program
Files\Syslogd\Logs"
oFileWatcher.FileName = "SyslogCatchAll.txt"
oFileWatcher.Constructor()
Do While 1 < 2
System.Threading.Thread.Sleep(400)
Loop
And here is some code from my class. I call the Sub Constructor now for
debugging purposes.
'-----------------------------------------
Class sysLogIoHandler code
'-----------------------------------------
Public Sub Constructor()
Dim oFileStream As System.IO.File
' Ensure that the file supports the properties we are to use later
on and then set the EOF position of the File
' Check if the file exists
sCompleteFileName = sFilePath & "\" & sFileName
If File.Exists(sCompleteFileName) = False Then
oWatcherEventLogger.LogEvent(Me.EventLogName, "File does not
exists or no access to the file :" & sFileName, EventLogEntryType.Error)
Exit Sub
End If
' Try to open a FileStream
Try
oWatcherFileSystemStream = (oFileStream.Open(sCompleteFileName,
FileMode.Open, FileAccess.Read, FileShare.None))
Catch ex As Exception
oWatcherEventLogger.LogEvent(Me.EventLogName, ex.ToString,
EventLogEntryType.Error)
End Try
' Check if the fileStream supports seeking
If oWatcherFileSystemStream.CanSeek = False Then
oWatcherEventLogger.LogEvent(Me.EventLogName, "The filestream
does not support Seeking" & sCompleteFileName, EventLogEntryType.Error)
Exit Sub
End If
'Set the EOF of the file property since we are to handle all
changes from here on.
lEofPosition = getCurrentEOF()
doWatchFileForChanges()
End Sub
Private Function getStreamsCurrentEOF() As Long
getStreamsCurrentEOF = CLng(oWatcherFileSystemStream.Length)
End Function
Public Function doWatchFileForChanges() As Boolean
Dim oWatcherFileWatcher As New FileSystemWatcher
'Set the path we are to watch
oWatcherFileWatcher.Path = sFilePath
'Set the Filter to just watch one file
oWatcherFileWatcher.Filter = sFileName
'Watch for increase in size or change of lastwrittenflag
oWatcherFileWatcher.NotifyFilter = NotifyFilters.LastWrite Or
NotifyFilters.Size
'Set a handler to the events we want to handle
AddHandler oWatcherFileWatcher.Changed, AddressOf
doWorkOnChangedFile
AddHandler oWatcherFileWatcher.Deleted, AddressOf
doWorkOnChangedFile
' Tell the FileWatcher to start working and raise events
oWatcherFileWatcher.EnableRaisingEvents = True
End Function
Private Sub doWorkOnChangedFile(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Select Case e.ChangeType
Case WatcherChangeTypes.Changed
Console.Write(doReadChangesInFile)
Case WatcherChangeTypes.Deleted
Console.Write("The file was deleted")
End Select
End Sub
Private Sub doNotifyThatFileIsNoMore(ByVal source As Object, ByVal e As
System.Io.FileSystemEventArgs)
End Sub
Private Function doReadChangesInFile() As String
If Me.getCurrentEOF = Me.getLastKnownEOF Then
oWatcherEventLogger.LogEvent(Me.EventLogName, "A 'Changed File
Event' Triggered and I'm trying to find the change but the filesize is the
same as lasttime i did this" & , EventLogEntryType.Error)
Return "" ' Return with no Data
End If
Dim iNumberOfBytes As Integer
' Get the number of bytes we are supposed to read
iNumberOfBytes = Me.getCurrentEOF - Me.getLastKnownEOF
' Prepare Buffer to read data into with the correct size
Dim abReaderBuffer(iNumberOfBytes) As Byte
' GoTo the last known EOF before the last change
oWatcherFileSystemStream.Seek(Me.getLastKnownEOF, SeekOrigin.Begin)
'Read the data into our buffer
oWatcherFileSystemStream.Read(abReaderBuffer, 0, iNumberOfBytes)
' set the next knownEOF since we have handled the changed data
lEofPosition = getCurrentEOF()
Return Encoding.ASCII.GetString(abReaderBuffer)
End Function 10 1674
most importantly.. what kind of system are you tring to run it on?
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl... Hi i'm an event Noob and i'm calling a class from my main module console
app like this. I'm sorry if this is a lot of code to read but i can't see the error according to my book. Thanks a LOT.
if there are other noobs here like me feel free to use my code if it's of any use :)
I've set a breakpoint at doWorkOnChangedFile but notinh happens... i'm flooding my log like hell.
Dim oFileWatcher As New sysLogIoHandler oFileWatcher.FileNamePathWithOutEndingSlash = "C:\Program Files\Syslogd\Logs" oFileWatcher.FileName = "SyslogCatchAll.txt" oFileWatcher.Constructor() Do While 1 < 2 System.Threading.Thread.Sleep(400) Loop
And here is some code from my class. I call the Sub Constructor now for debugging purposes.
'----------------------------------------- Class sysLogIoHandler code '-----------------------------------------
Public Sub Constructor()
Dim oFileStream As System.IO.File ' Ensure that the file supports the properties we are to use
later on and then set the EOF position of the File ' Check if the file exists sCompleteFileName = sFilePath & "\" & sFileName
If File.Exists(sCompleteFileName) = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "File does not exists or no access to the file :" & sFileName, EventLogEntryType.Error) Exit Sub End If
' Try to open a FileStream Try oWatcherFileSystemStream =
(oFileStream.Open(sCompleteFileName, FileMode.Open, FileAccess.Read, FileShare.None)) Catch ex As Exception oWatcherEventLogger.LogEvent(Me.EventLogName, ex.ToString, EventLogEntryType.Error) End Try
' Check if the fileStream supports seeking If oWatcherFileSystemStream.CanSeek = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "The filestream does not support Seeking" & sCompleteFileName, EventLogEntryType.Error) Exit Sub End If
'Set the EOF of the file property since we are to handle all changes from here on. lEofPosition = getCurrentEOF() doWatchFileForChanges()
End Sub
Private Function getStreamsCurrentEOF() As Long getStreamsCurrentEOF = CLng(oWatcherFileSystemStream.Length)
End Function
Public Function doWatchFileForChanges() As Boolean Dim oWatcherFileWatcher As New FileSystemWatcher 'Set the path we are to watch oWatcherFileWatcher.Path = sFilePath 'Set the Filter to just watch one file oWatcherFileWatcher.Filter = sFileName 'Watch for increase in size or change of lastwrittenflag oWatcherFileWatcher.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size 'Set a handler to the events we want to handle AddHandler oWatcherFileWatcher.Changed, AddressOf doWorkOnChangedFile AddHandler oWatcherFileWatcher.Deleted, AddressOf doWorkOnChangedFile
' Tell the FileWatcher to start working and raise events oWatcherFileWatcher.EnableRaisingEvents = True
End Function Private Sub doWorkOnChangedFile(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) Select Case e.ChangeType Case WatcherChangeTypes.Changed Console.Write(doReadChangesInFile) Case WatcherChangeTypes.Deleted Console.Write("The file was deleted") End Select End Sub
Private Sub doNotifyThatFileIsNoMore(ByVal source As Object, ByVal e
As System.Io.FileSystemEventArgs)
End Sub
Private Function doReadChangesInFile() As String If Me.getCurrentEOF = Me.getLastKnownEOF Then oWatcherEventLogger.LogEvent(Me.EventLogName, "A 'Changed
File Event' Triggered and I'm trying to find the change but the filesize is the same as lasttime i did this" & , EventLogEntryType.Error) Return "" ' Return with no Data End If Dim iNumberOfBytes As Integer ' Get the number of bytes we are supposed to read iNumberOfBytes = Me.getCurrentEOF - Me.getLastKnownEOF ' Prepare Buffer to read data into with the correct size Dim abReaderBuffer(iNumberOfBytes) As Byte ' GoTo the last known EOF before the last change oWatcherFileSystemStream.Seek(Me.getLastKnownEOF,
SeekOrigin.Begin) 'Read the data into our buffer oWatcherFileSystemStream.Read(abReaderBuffer, 0, iNumberOfBytes) ' set the next knownEOF since we have handled the changed data lEofPosition = getCurrentEOF() Return Encoding.ASCII.GetString(abReaderBuffer) End Function
Windows XP Pro. It's supposed to run on Windows 2003 server when done
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com... most importantly.. what kind of system are you tring to run it on?
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message news:u9**************@TK2MSFTNGP09.phx.gbl... Hi i'm an event Noob and i'm calling a class from my main module console app like this. I'm sorry if this is a lot of code to read but i can't see
the error according to my book. Thanks a LOT.
if there are other noobs here like me feel free to use my code if it's
of any use :)
I've set a breakpoint at doWorkOnChangedFile but notinh happens... i'm flooding my log like hell.
Dim oFileWatcher As New sysLogIoHandler oFileWatcher.FileNamePathWithOutEndingSlash = "C:\Program Files\Syslogd\Logs" oFileWatcher.FileName = "SyslogCatchAll.txt" oFileWatcher.Constructor() Do While 1 < 2 System.Threading.Thread.Sleep(400) Loop
And here is some code from my class. I call the Sub Constructor now for debugging purposes.
'----------------------------------------- Class sysLogIoHandler code '-----------------------------------------
Public Sub Constructor()
Dim oFileStream As System.IO.File ' Ensure that the file supports the properties we are to use later on and then set the EOF position of the File ' Check if the file exists sCompleteFileName = sFilePath & "\" & sFileName
If File.Exists(sCompleteFileName) = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "File does
not exists or no access to the file :" & sFileName, EventLogEntryType.Error) Exit Sub End If
' Try to open a FileStream Try oWatcherFileSystemStream = (oFileStream.Open(sCompleteFileName, FileMode.Open, FileAccess.Read, FileShare.None)) Catch ex As Exception oWatcherEventLogger.LogEvent(Me.EventLogName, ex.ToString, EventLogEntryType.Error) End Try
' Check if the fileStream supports seeking If oWatcherFileSystemStream.CanSeek = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "The
filestream does not support Seeking" & sCompleteFileName, EventLogEntryType.Error) Exit Sub End If
'Set the EOF of the file property since we are to handle all changes from here on. lEofPosition = getCurrentEOF() doWatchFileForChanges()
End Sub
Private Function getStreamsCurrentEOF() As Long getStreamsCurrentEOF = CLng(oWatcherFileSystemStream.Length)
End Function
Public Function doWatchFileForChanges() As Boolean Dim oWatcherFileWatcher As New FileSystemWatcher 'Set the path we are to watch oWatcherFileWatcher.Path = sFilePath 'Set the Filter to just watch one file oWatcherFileWatcher.Filter = sFileName 'Watch for increase in size or change of lastwrittenflag oWatcherFileWatcher.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size 'Set a handler to the events we want to handle AddHandler oWatcherFileWatcher.Changed, AddressOf doWorkOnChangedFile AddHandler oWatcherFileWatcher.Deleted, AddressOf doWorkOnChangedFile
' Tell the FileWatcher to start working and raise events oWatcherFileWatcher.EnableRaisingEvents = True
End Function Private Sub doWorkOnChangedFile(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) Select Case e.ChangeType Case WatcherChangeTypes.Changed Console.Write(doReadChangesInFile) Case WatcherChangeTypes.Deleted Console.Write("The file was deleted") End Select End Sub
Private Sub doNotifyThatFileIsNoMore(ByVal source As Object, ByVal
e As System.Io.FileSystemEventArgs)
End Sub
Private Function doReadChangesInFile() As String If Me.getCurrentEOF = Me.getLastKnownEOF Then oWatcherEventLogger.LogEvent(Me.EventLogName, "A 'Changed File Event' Triggered and I'm trying to find the change but the filesize is
the same as lasttime i did this" & , EventLogEntryType.Error) Return "" ' Return with no Data End If Dim iNumberOfBytes As Integer ' Get the number of bytes we are supposed to read iNumberOfBytes = Me.getCurrentEOF - Me.getLastKnownEOF ' Prepare Buffer to read data into with the correct size Dim abReaderBuffer(iNumberOfBytes) As Byte ' GoTo the last known EOF before the last change oWatcherFileSystemStream.Seek(Me.getLastKnownEOF, SeekOrigin.Begin) 'Read the data into our buffer oWatcherFileSystemStream.Read(abReaderBuffer, 0,
iNumberOfBytes) ' set the next knownEOF since we have handled the changed data lEofPosition = getCurrentEOF() Return Encoding.ASCII.GetString(abReaderBuffer) End Function
damn.. was hoping for NT, which FSW can't watch on... so lets actually look
into yoru code. =)
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message
news:OD**************@TK2MSFTNGP09.phx.gbl... Windows XP Pro. It's supposed to run on Windows 2003 server when done
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... most importantly.. what kind of system are you tring to run it on?
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message news:u9**************@TK2MSFTNGP09.phx.gbl... Hi i'm an event Noob and i'm calling a class from my main module
console app like this. I'm sorry if this is a lot of code to read but i can't see the error according to my book. Thanks a LOT.
if there are other noobs here like me feel free to use my code if it's of any use :)
I've set a breakpoint at doWorkOnChangedFile but notinh happens... i'm flooding my log like hell.
Dim oFileWatcher As New sysLogIoHandler oFileWatcher.FileNamePathWithOutEndingSlash = "C:\Program Files\Syslogd\Logs" oFileWatcher.FileName = "SyslogCatchAll.txt" oFileWatcher.Constructor() Do While 1 < 2 System.Threading.Thread.Sleep(400) Loop
And here is some code from my class. I call the Sub Constructor now
for debugging purposes.
'----------------------------------------- Class sysLogIoHandler code '-----------------------------------------
Public Sub Constructor()
Dim oFileStream As System.IO.File ' Ensure that the file supports the properties we are to use later on and then set the EOF position of the File ' Check if the file exists sCompleteFileName = sFilePath & "\" & sFileName
If File.Exists(sCompleteFileName) = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "File does not exists or no access to the file :" & sFileName,
EventLogEntryType.Error) Exit Sub End If
' Try to open a FileStream Try oWatcherFileSystemStream =
(oFileStream.Open(sCompleteFileName, FileMode.Open, FileAccess.Read, FileShare.None)) Catch ex As Exception oWatcherEventLogger.LogEvent(Me.EventLogName,
ex.ToString, EventLogEntryType.Error) End Try
' Check if the fileStream supports seeking If oWatcherFileSystemStream.CanSeek = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "The filestream does not support Seeking" & sCompleteFileName,
EventLogEntryType.Error) Exit Sub End If
'Set the EOF of the file property since we are to handle all changes from here on. lEofPosition = getCurrentEOF() doWatchFileForChanges()
End Sub
Private Function getStreamsCurrentEOF() As Long getStreamsCurrentEOF = CLng(oWatcherFileSystemStream.Length)
End Function
HERE IT IS.
you declare your FileWatcher in the wrong context. Don't declare its type
within a method, but declare it within the class
to make things easier you would declare it WithEvents, so you have
Public WithEvents oWatcher as FileSystemWatch
then in your method below
oWatcher = new FilesystemWatcher()
Public Function doWatchFileForChanges() As Boolean Dim oWatcherFileWatcher As New FileSystemWatcher 'Set the path we are to watch oWatcherFileWatcher.Path = sFilePath 'Set the Filter to just watch one file oWatcherFileWatcher.Filter = sFileName 'Watch for increase in size or change of lastwrittenflag oWatcherFileWatcher.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size 'Set a handler to the events we want to handle AddHandler oWatcherFileWatcher.Changed, AddressOf doWorkOnChangedFile AddHandler oWatcherFileWatcher.Deleted, AddressOf doWorkOnChangedFile
' Tell the FileWatcher to start working and raise events oWatcherFileWatcher.EnableRaisingEvents = True
End Function Private Sub doWorkOnChangedFile(ByVal source As Object, ByVal e
As System.IO.FileSystemEventArgs) Select Case e.ChangeType Case WatcherChangeTypes.Changed Console.Write(doReadChangesInFile) Case WatcherChangeTypes.Deleted Console.Write("The file was deleted") End Select End Sub
Private Sub doNotifyThatFileIsNoMore(ByVal source As Object,
ByVal e As System.Io.FileSystemEventArgs)
End Sub
Private Function doReadChangesInFile() As String If Me.getCurrentEOF = Me.getLastKnownEOF Then oWatcherEventLogger.LogEvent(Me.EventLogName, "A 'Changed File Event' Triggered and I'm trying to find the change but the filesize is the same as lasttime i did this" & , EventLogEntryType.Error) Return "" ' Return with no Data End If Dim iNumberOfBytes As Integer ' Get the number of bytes we are supposed to read iNumberOfBytes = Me.getCurrentEOF - Me.getLastKnownEOF ' Prepare Buffer to read data into with the correct size Dim abReaderBuffer(iNumberOfBytes) As Byte ' GoTo the last known EOF before the last change oWatcherFileSystemStream.Seek(Me.getLastKnownEOF, SeekOrigin.Begin) 'Read the data into our buffer oWatcherFileSystemStream.Read(abReaderBuffer, 0, iNumberOfBytes) ' set the next knownEOF since we have handled the changed
data lEofPosition = getCurrentEOF() Return Encoding.ASCII.GetString(abReaderBuffer) End Function
Whoops, forogto to tell you my comment for your fix is inline...(scroll down
in other message)
see previous post.
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message
news:OD**************@TK2MSFTNGP09.phx.gbl... Windows XP Pro. It's supposed to run on Windows 2003 server when done
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... most importantly.. what kind of system are you tring to run it on?
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message news:u9**************@TK2MSFTNGP09.phx.gbl... Hi i'm an event Noob and i'm calling a class from my main module
console app like this. I'm sorry if this is a lot of code to read but i can't see the error according to my book. Thanks a LOT.
if there are other noobs here like me feel free to use my code if it's of any use :)
I've set a breakpoint at doWorkOnChangedFile but notinh happens... i'm flooding my log like hell.
Dim oFileWatcher As New sysLogIoHandler oFileWatcher.FileNamePathWithOutEndingSlash = "C:\Program Files\Syslogd\Logs" oFileWatcher.FileName = "SyslogCatchAll.txt" oFileWatcher.Constructor() Do While 1 < 2 System.Threading.Thread.Sleep(400) Loop
And here is some code from my class. I call the Sub Constructor now
for debugging purposes.
'----------------------------------------- Class sysLogIoHandler code '-----------------------------------------
Public Sub Constructor()
Dim oFileStream As System.IO.File ' Ensure that the file supports the properties we are to use later on and then set the EOF position of the File ' Check if the file exists sCompleteFileName = sFilePath & "\" & sFileName
If File.Exists(sCompleteFileName) = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "File does not exists or no access to the file :" & sFileName,
EventLogEntryType.Error) Exit Sub End If
' Try to open a FileStream Try oWatcherFileSystemStream =
(oFileStream.Open(sCompleteFileName, FileMode.Open, FileAccess.Read, FileShare.None)) Catch ex As Exception oWatcherEventLogger.LogEvent(Me.EventLogName,
ex.ToString, EventLogEntryType.Error) End Try
' Check if the fileStream supports seeking If oWatcherFileSystemStream.CanSeek = False Then oWatcherEventLogger.LogEvent(Me.EventLogName, "The filestream does not support Seeking" & sCompleteFileName,
EventLogEntryType.Error) Exit Sub End If
'Set the EOF of the file property since we are to handle all changes from here on. lEofPosition = getCurrentEOF() doWatchFileForChanges()
End Sub
Private Function getStreamsCurrentEOF() As Long getStreamsCurrentEOF = CLng(oWatcherFileSystemStream.Length)
End Function
Public Function doWatchFileForChanges() As Boolean Dim oWatcherFileWatcher As New FileSystemWatcher 'Set the path we are to watch oWatcherFileWatcher.Path = sFilePath 'Set the Filter to just watch one file oWatcherFileWatcher.Filter = sFileName 'Watch for increase in size or change of lastwrittenflag oWatcherFileWatcher.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size 'Set a handler to the events we want to handle AddHandler oWatcherFileWatcher.Changed, AddressOf doWorkOnChangedFile AddHandler oWatcherFileWatcher.Deleted, AddressOf doWorkOnChangedFile
' Tell the FileWatcher to start working and raise events oWatcherFileWatcher.EnableRaisingEvents = True
End Function Private Sub doWorkOnChangedFile(ByVal source As Object, ByVal e
As System.IO.FileSystemEventArgs) Select Case e.ChangeType Case WatcherChangeTypes.Changed Console.Write(doReadChangesInFile) Case WatcherChangeTypes.Deleted Console.Write("The file was deleted") End Select End Sub
Private Sub doNotifyThatFileIsNoMore(ByVal source As Object,
ByVal e As System.Io.FileSystemEventArgs)
End Sub
Private Function doReadChangesInFile() As String If Me.getCurrentEOF = Me.getLastKnownEOF Then oWatcherEventLogger.LogEvent(Me.EventLogName, "A 'Changed File Event' Triggered and I'm trying to find the change but the filesize is the same as lasttime i did this" & , EventLogEntryType.Error) Return "" ' Return with no Data End If Dim iNumberOfBytes As Integer ' Get the number of bytes we are supposed to read iNumberOfBytes = Me.getCurrentEOF - Me.getLastKnownEOF ' Prepare Buffer to read data into with the correct size Dim abReaderBuffer(iNumberOfBytes) As Byte ' GoTo the last known EOF before the last change oWatcherFileSystemStream.Seek(Me.getLastKnownEOF, SeekOrigin.Begin) 'Read the data into our buffer oWatcherFileSystemStream.Read(abReaderBuffer, 0, iNumberOfBytes) ' set the next knownEOF since we have handled the changed
data lEofPosition = getCurrentEOF() Return Encoding.ASCII.GetString(abReaderBuffer) End Function
Thanks for your help CJ (Are you the same CJ that used to hang on
#windowsnt on irc back in 1997 ?)
Beaming a beer to you in return (damn... core dump... hmm damn debug)
However it still doesn't raise events... reading like hell over here...
I also tried adding this line after EnableRaisingEvents
oWatcherFileWatcher.EnableRaisingEvents = True
oWatcherFileWatcher.WaitForChanged(WatcherChangeTy pes.All)
but WaitForChanged never returns...
Are you using an actual event handler? I mean this is in the nicest way
possible, but do you understand event driven programming?
WaitForChanged only works on the last fired event. it doesn't actually
notify. It kinda works like a timer.
what you want to do is have aother method in there that is like this
WaitForChanged is basically
"Kai Thorsrud" <ka*********************@Start.no> wrote in message
news:Xn**********************************@207.46.2 48.16... Thanks for your help CJ (Are you the same CJ that used to hang on #windowsnt on irc back in 1997 ?)
Beaming a beer to you in return (damn... core dump... hmm damn debug)
However it still doesn't raise events... reading like hell over here... I also tried adding this line after EnableRaisingEvents
oWatcherFileWatcher.EnableRaisingEvents = True oWatcherFileWatcher.WaitForChanged(WatcherChangeTy pes.All)
but WaitForChanged never returns...
Private Shared Sub OnChanged(source As Object, e As FileSystemEventArgs) _
handles oWatcherFileWatcher.Created,
oWatcherFileWatcher.Changed, oWatcherFileWatch.Deleted, _
oWatcherFileWatcher.Renamed
' Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " & e.FullPath & " " & e.ChangeType)
End Sub
put a breakpoint on that one to see when the file watcher changes...
Asyncronous programming =)
Ahh yes, and as for windowsnt, yeah I did sometimes, but I remember a lot of
people did... a lot of people are named CJ too . =)
"Kai Thorsrud" <ka*********************@Start.no> wrote in message
news:Xn**********************************@207.46.2 48.16... Thanks for your help CJ (Are you the same CJ that used to hang on #windowsnt on irc back in 1997 ?)
Beaming a beer to you in return (damn... core dump... hmm damn debug)
However it still doesn't raise events... reading like hell over here... I also tried adding this line after EnableRaisingEvents
oWatcherFileWatcher.EnableRaisingEvents = True oWatcherFileWatcher.WaitForChanged(WatcherChangeTy pes.All)
but WaitForChanged never returns...
haha you really made my day.... Thanks a lot CJ.... are you the same CJ that
used to hang out on irc #windowsNT supporting ppl ? (I used to hang out
there a lot back in 1997 i don't remember my nick thou)
Beaming a cold beer right back to you (damn core dump... oh well in a few
years maybe)
/Kai
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com... Whoops, forogto to tell you my comment for your fix is inline...(scroll
down in other message)
see previous post.
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message news:OD**************@TK2MSFTNGP09.phx.gbl... Windows XP Pro. It's supposed to run on Windows 2003 server when done
"CJ Taylor" <no****@blowgoats.com> wrote in message news:10*************@corp.supernews.com... most importantly.. what kind of system are you tring to run it on?
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message news:u9**************@TK2MSFTNGP09.phx.gbl... > Hi i'm an event Noob and i'm calling a class from my main module console app > like this. I'm sorry if this is a lot of code to read but i can't
see the > error according to my book. > Thanks a LOT. > > if there are other noobs here like me feel free to use my code if
it's of > any use :) > > I've set a breakpoint at doWorkOnChangedFile but notinh happens...
i'm > flooding my log like hell. > > > Dim oFileWatcher As New sysLogIoHandler > oFileWatcher.FileNamePathWithOutEndingSlash = "C:\Program > Files\Syslogd\Logs" > oFileWatcher.FileName = "SyslogCatchAll.txt" > oFileWatcher.Constructor() > Do While 1 < 2 > System.Threading.Thread.Sleep(400) > Loop > > > And here is some code from my class. I call the Sub Constructor now
for > debugging purposes. > > '----------------------------------------- > Class sysLogIoHandler code > '----------------------------------------- > > Public Sub Constructor() > > Dim oFileStream As System.IO.File > ' Ensure that the file supports the properties we are to
use later > on and then set the EOF position of the File > ' Check if the file exists > sCompleteFileName = sFilePath & "\" & sFileName > > If File.Exists(sCompleteFileName) = False Then > oWatcherEventLogger.LogEvent(Me.EventLogName, "File
does not > exists or no access to the file :" & sFileName, EventLogEntryType.Error) > Exit Sub > End If > > ' Try to open a FileStream > Try > oWatcherFileSystemStream = (oFileStream.Open(sCompleteFileName, > FileMode.Open, FileAccess.Read, FileShare.None)) > Catch ex As Exception > oWatcherEventLogger.LogEvent(Me.EventLogName, ex.ToString, > EventLogEntryType.Error) > End Try > > ' Check if the fileStream supports seeking > If oWatcherFileSystemStream.CanSeek = False Then > oWatcherEventLogger.LogEvent(Me.EventLogName, "The filestream > does not support Seeking" & sCompleteFileName, EventLogEntryType.Error) > Exit Sub > End If > > 'Set the EOF of the file property since we are to handle
all > changes from here on. > lEofPosition = getCurrentEOF() > doWatchFileForChanges() > > End Sub > > > Private Function getStreamsCurrentEOF() As Long > getStreamsCurrentEOF =
CLng(oWatcherFileSystemStream.Length) > > End Function > > Public Function doWatchFileForChanges() As Boolean > Dim oWatcherFileWatcher As New FileSystemWatcher > 'Set the path we are to watch > oWatcherFileWatcher.Path = sFilePath > 'Set the Filter to just watch one file > oWatcherFileWatcher.Filter = sFileName > 'Watch for increase in size or change of lastwrittenflag > oWatcherFileWatcher.NotifyFilter = NotifyFilters.LastWrite
Or > NotifyFilters.Size > 'Set a handler to the events we want to handle > AddHandler oWatcherFileWatcher.Changed, AddressOf > doWorkOnChangedFile > AddHandler oWatcherFileWatcher.Deleted, AddressOf > doWorkOnChangedFile > > ' Tell the FileWatcher to start working and raise events > oWatcherFileWatcher.EnableRaisingEvents = True > > End Function > Private Sub doWorkOnChangedFile(ByVal source As Object, ByVal e As > System.IO.FileSystemEventArgs) > Select Case e.ChangeType > Case WatcherChangeTypes.Changed > Console.Write(doReadChangesInFile) > Case WatcherChangeTypes.Deleted > Console.Write("The file was deleted") > End Select > End Sub > > Private Sub doNotifyThatFileIsNoMore(ByVal source As Object, ByVal e As > System.Io.FileSystemEventArgs) > > End Sub > > Private Function doReadChangesInFile() As String > If Me.getCurrentEOF = Me.getLastKnownEOF Then > oWatcherEventLogger.LogEvent(Me.EventLogName, "A
'Changed File > Event' Triggered and I'm trying to find the change but the filesize
is the > same as lasttime i did this" & , EventLogEntryType.Error) > Return "" ' Return with no Data > End If > Dim iNumberOfBytes As Integer > ' Get the number of bytes we are supposed to read > iNumberOfBytes = Me.getCurrentEOF - Me.getLastKnownEOF > ' Prepare Buffer to read data into with the correct size > Dim abReaderBuffer(iNumberOfBytes) As Byte > ' GoTo the last known EOF before the last change > oWatcherFileSystemStream.Seek(Me.getLastKnownEOF, SeekOrigin.Begin) > 'Read the data into our buffer > oWatcherFileSystemStream.Read(abReaderBuffer, 0, iNumberOfBytes) > ' set the next knownEOF since we have handled the changed
data > lEofPosition = getCurrentEOF() > Return Encoding.ASCII.GetString(abReaderBuffer) > End Function > > >
Hi again!
I just came home from work and i've been playing around with the code for a
while... It turns out there is nothing wrong with my code...
I changed the code to monitor the entire directory and it triggers if i have
a text file in the directory and i open the text file in textpad and change
that file....
However it wont trigger on my Kiwi Syslog Deamon's log file ( The
SyslogDeamon is running and windows explorer updates the logfile's
attributes everytime the logfile get's updated).
The logfile has a lock on it. i can open the logfile in textpad but i can't
write to it since there is a write lock on it...
Is this a limitation of the FileSystemWatcher ? If so is there a way around
this ? Darn fck'in stupid FileSystemWatcher if it is so.... The windows
Explorer sure notify the changes in the file and update's it's size and file
attributes...
/Kai
"Kai Thorsrud" <ka*********************@Start.no> wrote in message
news:Xn**********************************@207.46.2 48.16... Thanks for your help CJ (Are you the same CJ that used to hang on #windowsnt on irc back in 1997 ?)
Beaming a beer to you in return (damn... core dump... hmm damn debug)
However it still doesn't raise events... reading like hell over here... I also tried adding this line after EnableRaisingEvents
oWatcherFileWatcher.EnableRaisingEvents = True oWatcherFileWatcher.WaitForChanged(WatcherChangeTy pes.All)
but WaitForChanged never returns...
damn stupid me... i have solved it... in my contructor i also open this log
file for reading to have a stream ready for the event which is supposed to
read the changes in the log file :D
"Kai Thorsrud" <ka******@thispartgoesaways.start.no> wrote in message
news:en**************@TK2MSFTNGP11.phx.gbl... Hi again!
I just came home from work and i've been playing around with the code for
a while... It turns out there is nothing wrong with my code... I changed the code to monitor the entire directory and it triggers if i
have a text file in the directory and i open the text file in textpad and
change that file....
However it wont trigger on my Kiwi Syslog Deamon's log file ( The SyslogDeamon is running and windows explorer updates the logfile's attributes everytime the logfile get's updated). The logfile has a lock on it. i can open the logfile in textpad but i
can't write to it since there is a write lock on it...
Is this a limitation of the FileSystemWatcher ? If so is there a way
around this ? Darn fck'in stupid FileSystemWatcher if it is so.... The windows Explorer sure notify the changes in the file and update's it's size and
file attributes...
/Kai
"Kai Thorsrud" <ka*********************@Start.no> wrote in message news:Xn**********************************@207.46.2 48.16... Thanks for your help CJ (Are you the same CJ that used to hang on #windowsnt on irc back in 1997 ?)
Beaming a beer to you in return (damn... core dump... hmm damn debug)
However it still doesn't raise events... reading like hell over here... I also tried adding this line after EnableRaisingEvents
oWatcherFileWatcher.EnableRaisingEvents = True oWatcherFileWatcher.WaitForChanged(WatcherChangeTy pes.All)
but WaitForChanged never returns...
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Josh Usovsky |
last post by:
I'm setting up a watched folder using FileSystemWatcher.
When I drop a small file into the watched folder, I can
respond to a .Created event and process the file with
other code. However, if I try...
|
by: cxw0106 |
last post by:
Hello,
I have some weird problem with the FileSystemWatcher. I have developed
an application that monitors a network directory for file changes of a
certain file type. The program runs well for...
|
by: Jet Leung |
last post by:
Hi all,
I had made a program to watching files in my directory. I had used a
instance of FileSystemWatcher to do my work.And I had add some events of the
FileSystemWatcher , for example onChange,...
|
by: Jon Maz |
last post by:
Hi there,
I am experimenting with the FileSystemWatcher object. I have set the
NotifyFilter as follows:
myFileSystemWatcher.NotifyFilter = NotifyFilters.Security |
NotifyFilters.CreationTime...
|
by: John Lee |
last post by:
Hi,
I developed a filewatcher service to monitor file creation on a network
drive - 90% time it works fine and from time to time I found out that the
newly created file on that network drive...
|
by: Stampede |
last post by:
Hi,
I write an application which waits for incomming files in a specified
directory. I thought, that using the FileSystemWatcher would be the best, as
it does exactly what I need.
But now I have...
|
by: Stampede |
last post by:
Hi,
I want to use the FileSystemWatcher in a Windows Service. I read an article,
where the author created the FileSystemWatcher object in a seperate thread
and when the event is fired, he started...
|
by: kmcnet |
last post by:
Hello Everyone and thanks for your help in advance. I have been battling a
problem for nearly a month with the FileSystemWatcher component. Basically,
what I am trying to do it to monitor three...
|
by: ljh |
last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event
twice when a file is changed?
Do you have any idea why this is the case?
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |