IOException: The process cannot access the file ‘file path’ because it is being used by another process
Issue Description
Today in this article, we will cover below aspects,
Updated October 2026: a section on finding the locking process, a section on FileAccess/FileShare with a C# retry example, and an FAQ.
While performing an operation on file produces an error as below,
IOException:The process cannot access the file 'file' because it is being used by another process.

Resolution
This error means, the file which you are trying to access is not accessible because,
- The file may be in use by some other process.
- The file is open by the Own process (maybe due to coding issues).
- The file property is set to not share while reading or writing the file.
This issue could occure when perfroming any operations like
– Read
– Write
– Delete
This issue can be resolved by carefully following all possible approaches based on how your application is dealing with files.
Solution 1 –The file may be in use by some other process
- Please make sure to verify the file is not opened by another process.
This could be any specific process on the system or program opening the file at the time when your program or application is already using it.
Its important how different methods are being used in the code. There are multiple ways to deal with File Open, Create, Read, or write operations.
A few examples of File related methods but not limited are as below,
File.Create
File.Open
File.ReadAllText()
File.WriteAllText()
File.ReadAllLines()
File.WriteAllLines()
Example
// Create the file, or overwrite if the file exists.
using (FileStream fs = File.Create(path))
{
byte[] info = new UTF8Encoding(true).GetBytes("This is test file.");
// Add details to the file.
fs.Write(info, 0, info.Length);
}
Note: When using File.Create, please note FileShare value of None is used as default behavior i.e no other process or code can access the file until the original file handle is closed.
Understand File Enumeration to Solve File access issues,
While using FileStream class, you get the ability to specify the FileShare access type another process can have while dealing with File Processing. FileStream class supports the below types,
- FileShare.ReadWrite
- FileShare.Write
- FileShare.Read
- FileShare.None
For more information and best practices, please visit the below article.
Proper use of FileShare enumeration will help you resolve the most common issues while dealing with files.
How to Find Which Process Is Locking a File in Windows
Use PowerToys File Locksmith, Resource Monitor or Sysinternals Process Explorer to see which process holds a handle on the file. Once you know the owner, you can decide whether to close it, change it or add a retry.
In plain English: A handle is like a checkout slip at a library desk. The file stays “checked out” until the process that holds the slip returns it, and these tools show you who is holding the slip.
Which tool should you use?
This table compares the three built-in or free options.
| Tool | Best for | Catch |
|---|---|---|
| File Locksmith | Fast answer, build scripts | Needs PowerToys installed |
| Resource Monitor | Nothing to install | Handle search can be slow |
| Process Explorer / Handle | Closing a single handle | Run elevated to see everything |
How do you use Resource Monitor?
Resource Monitor ships with Windows, so it works on any machine.
- Open it: press Win+R and run
resmon. - Go to the CPU tab: expand Associated Handles.
- Search: type part of the file name and read the process column.
This search can take a long time on a busy machine. If it hangs, switch to File Locksmith.
How do you use PowerToys File Locksmith?
File Locksmith adds a right-click option in Explorer that lists the processes using the selected file or folder. It also has a command-line interface that lists locking processes and can output JSON.
For build scripts, the --wait option blocks until the file is released. Add --timeout (in milliseconds) so the script doesn’t hang forever. Check the PowerToys docs for the exact syntax of your installed version.
How do you use Process Explorer or Handle?
In Process Explorer, press Ctrl+F to open Find Handle or DLL, then search for the file name. From the result you can close the handle or end the process. The Handle command-line tool does the same job from an elevated prompt. Run both as administrator, or you’ll miss handles owned by other users and services.
For files opened through a Windows network share, use openfiles instead.
Is it safe to kill the locking process?
Not automatically. Knowing the owner doesn’t mean you should end it. Close the application normally first. Use File Locksmith’s --kill option or End Task only when you know what the process is and what it might lose.
The same error appears at build time. If the build can’t copy the .exe or .dll into bin\Debug, your app is probably still running or a debugger is attached. Stop it, then rebuild.
Sometimes nothing shows up. Antivirus and backup tools can lock a file only briefly while they scan or copy it, and that’s often too short for any handle tool to catch. If the error is intermittent and the tools show nothing, the retry pattern in Solution 4 is the right fix.
Solution 2 – Implements IDisposable for Files handles
It’s always safe to use the “using” statement while dealing with files instead of creating and managing the instance ourselves.
Wrap all your code inside “Using” statements.

For more information and best practices, please visit the below article.
Solution 3 – Implement File Lock, Unlock – Thread Synchronization
- The file can be accessed by multiple threads within the application or by external process threads.
- If you have multiple threads attempting to access the same file, consider using a Synchronization mechanism using Lock or another threading synchronization mechanism.
- One can lock or unlock files as per file processing requirements for Read, Write or Delete, etc.
For more information and best practices, please visit the below article.
Solution 4 – Implement a Retry pattern for File processing
This is not mandatory but always come in handy while dealing with file exceptions or temporary glitch accessing the file.
For more information and best practices, please visit the below article.
References:
For more information and best practices, please visit the below article.
That’s all! Happy coding!
Does this help you fix your issue?
Do you have any better solutions or suggestions? Please sound off your comments below.
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.
Frequently asked questions
What does ‘the process cannot access the file because it is being used by another process’ mean?
Another process, or your own code, has the file open with a sharing mode that blocks the access you’re asking for. It can happen on read, write, delete, move or copy. The fix is to close whatever holds the file, or to change the share mode so both handles can coexist.
Can antivirus or a backup job cause this file-in-use error?
Yes. Antivirus scanners and backup tools can lock a file for a moment while they work on it, often too briefly to show up in handle tools. Retry with a short backoff, and for recurring cases exclude the folder from scanning. If scheduled tasks hit the same file, stagger them so they don’t overlap.
What does FileShare.ReadWrite do and when should I use it?
It lets other handles open the file for reading and writing while yours is open. Use it for something like a log file that one process writes while another reads or tails it. Every handle already open on the file must also allow that sharing, and readers may see partially written data.
Why do I get this error with Windows Update (0x80070020)?
The same message appears there because another program is using files the update needs. Do a clean boot with msconfig so third-party startup programs don’t run, then retry the update.
