Answers for "the process cannot access the file because it is being used by another process. c#"

C#
-1

the process cannot access the file because it is being used by another process. c#

private const int NumberOfRetries = 3;
private const int DelayOnRetry = 1000;

for (int i=1; i <= NumberOfRetries; ++i) {
    try {
        // Do stuff with file
        break; // When done we can break loop
    }
    catch (IOException e) when (i <= NumberOfRetries) {
        // You may check error code to filter some exceptions, not every error
        // can be recovered.
        Thread.Sleep(DelayOnRetry);
    }
}
Posted by: Guest on May-15-2021

Code answers related to "the process cannot access the file because it is being used by another process. c#"

C# Answers by Framework

Browse Popular Code Answers by Language