Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hello
I need too monitor all local driver so I code this
VB
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim allDrives2() As IO.DriveInfo = IO.DriveInfo.GetDrives()
    Dim dd As IO.DriveInfo
    Dim N As Integer = 0
    Dim T(10) As FileSystemWatcher
    For Each dd In allDrives2
        If dd.IsReady = True Then
            T(N).Path = dd.Name
            T(N).IncludeSubdirectories = True
            T(N).EnableRaisingEvents = True
            N = N + 1
        End If
    Next
    
End Sub


put I have error !
can someone correct it ?
Thank you
Posted
Updated 1-Jan-13 2:38am
v3
Comments
Richard MacCutchan 1-Jan-13 8:51am    
What error?
Abhinav S 1-Jan-13 10:02am    
Try debugging to figure out the error.

First:
Dim T(10) As FileSystemWatcher
The number of drives might more than that

Second:
T(N) is null or Nothing, new instance of FileSystemWatcher required

VB
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim allDrives2() As IO.DriveInfo = IO.DriveInfo.GetDrives()
    Dim N As Integer = 0
    Dim T(allDrives2.Length - 1) As IO.FileSystemWatcher
    For Each dd As IO.DriveInfo In allDrives2
        If dd.IsReady = True Then
            T(N) = New IO.FileSystemWatcher
            T(N).Path = dd.Name
            T(N).IncludeSubdirectories = True
            T(N).EnableRaisingEvents = True
            N += 1
        End If
    Next
End Sub
 
Share this answer
 
You have a bigger problem. The FSW was not designed to watch an entire drive. You'll have problems with it and miss events. It may also use enough resources to bring the system to a crawl.

Test TEST and MORE TEST!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900