CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2002
    Location
    presently in SouthKorea
    Posts
    116

    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]

  2. #2
    Join Date
    Nov 2002
    Posts
    34
    Hi,

    if you have found the solution could you please send me an example?

    Thank you

  3. #3
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    I'd think you could fireup a thread for each drive you want to watch.

  4. #4
    Join Date
    Nov 2002
    Posts
    34
    i think there is no need it will be watched using windows service app.

  5. #5
    Join Date
    Jul 2002
    Location
    presently in SouthKorea
    Posts
    116
    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

  6. #6
    Join Date
    Nov 2002
    Posts
    34
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured