C# error messages are usually very clear to understand but sometimes it’s hard to find a good way to solve the problem. Especially with I/O operations we need some tricks.
While closing a file with C# via StreamReader, StreamWriter, fopen, fclose, etc. and get this error: “The process cannot access the file, because it is being used by another process” even if closing, giving null value and disposing the identifier is not working, there’s a simple way to do:
This command will run GarbageCollector and removes this error from the ErrorList.