Boolean Boolean - 9 months ago 93
C# Question

C# Problem with opened files

Possible Duplicate:

Is there a way to check if a file is in use?

Is there a way to close a file in C#?


The above code complains that file is already used by another process.

Is there a way to check the open file handles in VS 2008?

Answer Source

Close any streams using the file in your application.

If the error is due to another running applicaton, it's best to just try the operation, and deal with the failure. If you check, then try to perform the operation, you create a race condition. If the delete fails (whether due to file in use or permissions), just deal with the problem then.