-
filesystemwatcher
Hi
I need a service type application , which watches wholes system for the changed files by using filesystemewatcher component. I implemented a service which can watch onely one root like "C:\". but i need to watch whole system like "C:\","D:\".....etc. How should i achieve this. I want this to be done in VB.net. can anyone please send me some sample application whcih can do this?
please reply me as early as possible
Thanking you sri
Regards
Praveen.P
[email protected]
-
Hi,
if you have found the solution could you please send me an example?
Thank you
-
I'd think you could fireup a thread for each drive you want to watch.
-
i think there is no need it will be watched using windows service app.
-
Hi,
i am initiating for each drive different thread in windows service starting. if you know betterway please let me know.
Dim fso As New Scripting.FileSystemObject()
Dim drive As Scripting.Drive
For Each drive In fso.Drives
If drive.DriveType = Scripting.DriveTypeConst.Fixed Then
Dim t As System.Threading.Thread = SimpleThread.CreateThread(AddressOf InitFilewatcherThread, drive.Path & "\")
t.Priority = Threading.ThreadPriority.Highest
t.Start()
End If
Next
Regards
praveenp
-
I'm not sure whether this way is better I'm just not using threads.
Code:
Dim fsWatcher(-1) As System.IO.FileSystemWatcher
Private Sub addWatcher(ByVal strPath As String, ByVal strFilter As String)
ReDim Preserve fsWatcher(UBound(fsWatcher) + 1)
fsWatcher(UBound(fsWatcher)) = New System.IO.FileSystemWatcher(strPath, strFilter)
fsWatcher(UBound(fsWatcher)).EnableRaisingEvents = True
fsWatcher.IncludeSubdirectories = True
AddHandler fsWatcher(UBound(fsWatcher)).Changed, AddressOf fsEventHandler
End Sub
Private Sub fsEventHandler(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
MsgBox(e.FullPath)
End Sub
Private Sub RemoveAllWatchers()
Dim i As Integer
For i = 0 To UBound(fsWatcher)
fsWatcher(i).Dispose()
RemoveHandler fsWatcher(i).Changed, AddressOf fsEventHandler
Next
End Sub
Maybe this way it is a little bit easier to control created objects...