title: What causes DriveInfo.IsReady to be false?
body: <h1>Situation</h1>
  
  <p>I'm debugging some legacy code that performs some existence checks on directory paths. First, <code>DirectoryPathA</code> is checked and returned if it exists. This should be the usual case. If that fails, <code>DirectoryPathB</code> is checked and returned. (If that fails too, other things happen, not part of this question). Here's how the code looks:</p>
  
  <pre><code>if (!string.IsNullOrEmpty(DirectoryPathA))
  {
      driveInfo = new DriveInfo(DirectoryPathA);
      if (driveInfo.IsReady)
      {
          dInf = new DirectoryInfo(DirectoryPathA);
          if (dInf.Exists)
          {
              return DirectoryPathA;
          }
      }
  }
  
  if (!string.IsNullOrEmpty(DirectoryPathB))
  {
      dInf = new DirectoryInfo(DirectoryPathB);
      if (dInf.Exists)
      {
          return DirectoryPathB;
      }
  }
  </code></pre>
  
  <p>As you can see, the first check has an additional guard based on <a href="https://docs.microsoft.com/en-us/dotnet/api/system.io.driveinfo.isready?view=netframework-4.5" rel="noreferrer"><code>DriveInfo.IsReady</code></a>. There have been problems with file access on the network before, so my assumption is (again, this is legacy code) that this was introduced to establish <code>DirectoryPathB</code>as an alternative if <code>DirectoryPathA</code> is not available. I have no idea why no such check for <code>DriveInfo.IsReady</code> is performed on <code>DirectoryPathB</code>.</p>
  
  <h1>Problem</h1>
  
  <p>Even if <code>DirectoryPathA</code> is a local directory (so no network outage), the code above <strong>sporadically</strong> returns <code>DirectoryPathB</code>. The code is executed several times and is assumed to be idempotent, which it is not, which breaks things.
  This only happens occasionally on some machines over the course of several hours. I cannot reproduce the problem.</p>
  
  <p>There's a fundamental problem with the assumption that the drive state would never change throughout the execution of a program. I understand that. However, this code seems to be fine most of the time and has been in the past.</p>
  
  <h1>Question</h1>
  
  <p><strong>What can cause <code>DriveInfo.IsReady</code> to be <code>false</code>?</strong></p>
  
  <p>The documentation states</p>
  
  <blockquote>
    <p><code>true</code> if the drive is ready; <code>false</code> if the drive is not ready.</p>
  </blockquote>
  
  <p>Thanks for nothing. The remarks section adds</p>
  
  <blockquote>
    <p>IsReady indicates whether a drive is ready. For example, it indicates whether a CD is in a CD drive or whether a removable storage device is ready for read/write operations. If you do not test whether a drive is ready, and it is not ready, querying the drive using DriveInfo will raise an IOException.</p>
  </blockquote>
  
  <ul>
  <li>It's not a removable drive. We're talking plain old <code>C:\</code>.</li>
  <li>It's not a permission issue because it sometimes works and sometimes doesn't for the same user.</li>
  <li>It's not a matter of the drive becoming unavailable due to power saving mode, because 
  
  <ul>
  <li>power saving mode is not active and</li>
  <li>it's an SSD.</li>
  </ul></li>
  </ul>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/system.io.driveinfo(v=vs.110).aspx#Thread%20Safety" rel="noreferrer">The old documentation</a> states that</p>
  
  <blockquote>
    <h1>Thread Safety</h1>
    
    <p>Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.</p>
  </blockquote>
  
  <p>Does that mean that <code>DriveInfo.IsReady</code> might be <code>false</code> if some other thread is performing some operation on the drive at the same time?
  Is it even necessary for <code>DriveInfo.IsReady</code> to be <code>true</code> in order to check if a directory exists?</p>