Click here to Skip to main content
11,718,589 members (59,566 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET IO
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.3K
Edited 1-Jan-13 2:38am
v3
Comments
Richard MacCutchan at 1-Jan-13 8:51am
   
What error?
Abhinav S at 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
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2015
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