Click here to Skip to main content
Sign Up to vote bad
good
See more: VB.NETIO
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:08
kosay85890
Edited 1 Jan '13 - 2:38

Comments
Richard MacCutchan - 1 Jan '13 - 8:51
What error?
Abhinav S - 1 Jan '13 - 10:02
Try debugging to figure out the error.

2 solutions

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  
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 409
1 Mahesh Bailwal 353
2 Maciej Los 260
3 CPallini 245
4 Aarti Meswania 173
0 Sergey Alexandrovich Kryukov 9,162
1 OriginalGriff 7,194
2 CPallini 3,923
3 Rohan Leuva 3,176
4 Maciej Los 2,633


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid