Source/NFX/IOMiscUtils.cs
/// <summary>
/// Tries to delete the specified directory if it exists BLOCKING for up to the specified interval until directory is PHYSICALLY deleted.
/// Returns true when directory either did not exist in the first place or was successfully deleted (with confirmation).
/// Returns false when directory could not be confirmed to be deleted within the specified timeout, this does not mean
///  that the OS will not delete the directory later, so calling this function in a loop is expected.
///  NOTE: Directory.Delete() does not guarantee that directory is no longer on disk upon its return
/// </summary>
/// <param name="dirName">Directory to delete</param>
/// <param name="timeoutMs">Timeout in ms</param>
Tries to delete the specified directory if it exists BLOCKING for up to the specified interval until directory is PHYSICALLY deleted.
Returns true when directory either did not exist in the first place or was successfully deleted (with confirmation).
Returns false when directory could not be confirmed to be deleted within the specified timeout, this does not mean
that the OS will not delete the directory later, so calling this function in a loop is expected.
NOTE: Directory.Delete() does not guarantee that directory is no longer on disk upon its return
Tries to delete the specified directory if it exists BLOCKING for up to the specified interval until directory is PHYSICALLY deleted . Returns true when directory either did not exist in the first place or was successfully deleted ( with confirmation ) . Returns false when directory could not be confirmed to be deleted within the specified timeout this does not mean that the OS will not delete the directory later so calling this function in a loop is expected . NOTE : Directory . Delete () does not guarantee that directory is no longer on disk upon its return
public static bool EnsureDirectoryDeleted(string dirName, int timeoutMs = IO_WAIT_DEFAULT_TIMEOUT)
        {
          if (dirName.IsNullOrWhiteSpace()) return false;
          if (timeoutMs<IO_WAIT_MIN_TIMEOUT) timeoutMs = IO_WAIT_MIN_TIMEOUT;
          if (!Directory.Exists(dirName)) return true;
          Directory.Delete(dirName, true);
          var sw = System.Diagnostics.Stopwatch.StartNew();
          while(sw.ElapsedMilliseconds < timeoutMs)
          {
             if (!Directory.Exists(dirName)) return true;
             System.Threading.Thread.Sleep(IO_WAIT_GRANULARITY_MS);
          }
          return false;
        }
public static bool EnsureDirectoryDeleted ( string dirName , int timeoutMs = IO_WAIT_DEFAULT_TIMEOUT ) { if ( dirName . IsNullOrWhiteSpace ( ) ) return false ; if ( timeoutMs < IO_WAIT_MIN_TIMEOUT ) timeoutMs = IO_WAIT_MIN_TIMEOUT ; if ( ! Directory . Exists ( dirName ) ) return true ; Directory . Delete ( dirName , true ) ; var sw = System . Diagnostics . Stopwatch . StartNew ( ) ; while ( sw . ElapsedMilliseconds < timeoutMs ) { if ( ! Directory . Exists ( dirName ) ) return true ; System . Threading . Thread . Sleep ( IO_WAIT_GRANULARITY_MS ) ; } return false ; }
Tries to delete the specified directory if it exists BLOCKING for up to the specified interval until directory is PHYSICALLY deleted.
Tries to delete the specified directory if it exists BLOCKING for up to the specified interval until directory is PHYSICALLY deleted .
//MARKS directory for deletion, but does not delete it //actual check for physical presence on disk
dirName
string
Directory to delete
Directory to delete
timeoutMs
int
Timeout in ms
Timeout in ms