I am writing a program that will constantly be reading information from a disc in the disc drive.
To accomplish this, I am using the following code.

if (Directory.Exists(@"D:\"))
        {
            DirectoryInfo LookingAtDir = new DirectoryInfo(@"D:\");
            FileInfo[] Files = LookingAtDir.GetFiles("*.txt");

            foreach (FileInfo IndividualFile in Files)
            {
                File.ReadAllBytes(IndividualFile.FullName);
                File.ReadAllLines(IndividualFile.FullName);
                File.ReadAllText(IndividualFile.FullName);
            }
        }

When I run my program, I don't notice my disc drive spinning.
Am I right to assume that my C# program isn't actually reading from the disc?
If so, any recommendations as to how I can achieve my goal?

Thanks.

Put break point at foreach statment and start debug your application. You can also check the length of files array.

if (Directory.Exists(@"D:\"))
            {
                DirectoryInfo LookingAtDir = new DirectoryInfo(@"d:\");
                FileInfo[] Files = LookingAtDir.GetFiles("*.txt");

                //Debug statement
                System.Diagnostics.Debug.Assert(Files.Length!=0,"No files");
 
                foreach (FileInfo IndividualFile in Files)
                {
                     
                    byte ar[]=File.ReadAllBytes(IndividualFile.FullName);

                    //Another debug statement - output will be written at Output window.
                    System.Diagnostics.Debug.WriteLine("Size of file is : {0}",ar.Length);
                }
            }

The method FileReadAllBytes(..) return an array of bytes which the content of a file so you may receive array of bytes using,

byte[]ar=File.ReadAllText(IndividualFile.FullName);
This article has been dead for over six months. Start a new discussion instead.