Click here to Skip to main content
13,195,146 members (66,353 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hello
I need too monitor all local driver so I code this
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 1-Jan-13 2:08am
kosay851.4K
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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!
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171019.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100