Now, let's see how to monitor hard drives.
You can use the class
System.IO.DriveInfo
, please see
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx[
^].
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
if (drive.IsReady) {
long freeSpace = drive.TotalFreeSpace;
long size = drive.TotalSize;
string name = drive.Name;
ReportDriveInfo(freeSpace, size, name );
} else
}
Also, you can use
push technology (
http://en.wikipedia.org/wiki/Push_technology[
^]) in monitoring drives. Instead of polling data periodically, which is always not very good, you can subscribe to some file system events and avoid polling data if nothing essential has changed. For this purpose, you can use the class
System.IO.FileSystemWatcher
; please see:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[
^].
You may find the idea of push technology very useful if you remember that file operations are relatively expensive, so you want to reduce number of polls.
—SA