0

I used the example code from msdn to list all the drives in a system:

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
    Console.WriteLine("Drive {0}", d.Name);
    Console.WriteLine("  Drive type: {0}", d.DriveType);
    if (d.IsReady == true)
    {
        Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
        Console.WriteLine("  File system: {0}", d.DriveFormat);
        Console.WriteLine(
            "  Available space to current user:{0, 15} bytes", 
            d.AvailableFreeSpace);

        Console.WriteLine(
            "  Total available space:          {0, 15} bytes",
            d.TotalFreeSpace);

        Console.WriteLine(
            "  Total size of drive:            {0, 15} bytes ",
            d.TotalSize);
    }
}

when I run this exe on a cluster setup which has 7 drives, 1 physical and 6 cluster drives. EXE takes 1 minute to display the info of 2 particular drives.

The delay seems to be caused on the d.IsReady call.

I need to reduce the time. what could be the possible root cause for this issue?

rene
  • 41,474
  • 78
  • 114
  • 152
  • I would start by using the [Stopwatch](https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx) class to time each call and narrow it down. – Quantic Aug 18 '16 at 16:55
  • I used the timestamp class to get the delay in execution. I believe that driveinfo class takes some time to compute details of particular cluster drives. But now I need to know how could I reduce its computation processed by driveinfo class – Madhukiran Ns Aug 18 '16 at 17:44
  • 1
    Yes, and we ask you to specify which of the specific properties take a long time because I can't imagine that the `DriveInfo.GetDrives();` takes a long time but `d.AvailableFreeSpace` might. Knowing that might influence the answer. Also please add the exact code you're using to your question. – rene Aug 18 '16 at 17:54
  • @rene exactly as you said! DriveInfo.GetDrives(); doesn't take more than a second! I have a link in my question! There is a sample code in that link. In the foreach loop, it checks whether the drive is ready! Once it is ready it starts printing the complete info about the drive! So why does it takes more than a minute to check whether it is ready? Because the drive name is already fetched in GetDrives(). And how could I reduce that time taken to check the ready state of the drive? – Madhukiran Ns Aug 18 '16 at 18:02
  • Questions without code and only a link are down voted and closed here. If you want to have great answers make sure your question is great. – rene Aug 18 '16 at 18:08
  • 1
    Is it a normal drive letter or an unc path when IsReady hangs? – rene Aug 18 '16 at 18:13
  • by the look of the output on the console, it looks like its a UNC path, do you notice any delays when manually checking your drive's properties ? – Stavm Aug 18 '16 at 18:14
  • Those two drives are shared drives with another node in cluster group. I didn't try to check the properties of the drive. Will try this and update the thread. – Madhukiran Ns Aug 18 '16 at 18:21
  • related: http://stackoverflow.com/questions/1142080/how-to-avoid-network-stalls-in-getfileattributes because under the hood IsReady calls [`GetFileAttributesEx`](https://msdn.microsoft.com/nl-nl/library/windows/desktop/aa364946(v=vs.85).aspx). It might be a disk driver issue. – rene Aug 18 '16 at 18:21
  • most likely some network or hardware issue, i would suggest you try using this example: http://stackoverflow.com/questions/21421891/get-disk-space-information-from-multiple-remote-windows-servers?answertab=active#tab-top which does this same thing using window's wmic - seeif you encounter same issues, if you do, most likely not something that can be solved through code, but rather network or hardware issue. – Stavm Aug 18 '16 at 18:23
  • Thanks for all the suggestions! – Madhukiran Ns Aug 18 '16 at 18:28
  • In that system one of the drive is not accessible. hence drive.isready api took time to get the status of that drive. If I skip that specific drive it worked within 2 seconds. Thanks. – Madhukiran Ns Aug 22 '16 at 09:10

0 Answers0