Monitor all drives on computer with FileSystemWatcher [closed]

  .net, c++, filesystemwatcher, windows

I am using FileSystemWatcher to monitor all drives on my computer but after running the application the monitoring unfortunately does not work properly (It does not work on all drives). What could I have done wrong in the code below?

protected override void OnStart(string[] args)
    {
        string[] @drives = @Environment.GetLogicalDrives();
        DriveInfo @di = null;
        for (int @i = 0; @i < @drives.Length; @i++)
        {
            @di = new DriveInfo(@drives[@i]);
            if (@di.IsReady)
            {
                FileSystemWatcher @watcher = new FileSystemWatcher();
                @watcher.Filter = "*.*";
                @watcher.Path = @drives[@i];
                @watcher.IncludeSubdirectories = true;
                @watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Attributes | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.CreationTime | NotifyFilters.Security;
                @watcher.Deleted += new FileSystemEventHandler(RealTime);
                @watcher.Renamed += new RenamedEventHandler(RealTime);
                @watcher.Changed += new FileSystemEventHandler(RealTime);
                @watcher.Created += new FileSystemEventHandler(RealTime);
                @watcher.EnableRaisingEvents = true;
                watchers.Add(@watcher);
            }
        }
    }

The program should monitor all drives but it doesn’t and I don’t know what the problem is

Source: Windows Questions

LEAVE A COMMENT