File.Delete "The process cannot access the file ... because it is being used by another process."
Posted on 2014-10-17
I'm having to maintain a C# program that is using File.WriteAllLines to write a file to disk. I've needed to create at temp file to read back in and change some data based on data in another file read in.
I want to delete the temp file when I leave so the user won't have the intermediate file to get confused with, but I get an error: "The process cannot access the file ... because it is being used by another process."
How do I "free" this intermediate file? I don't see a Close method on File and nothing that I can find that sends back a handle that I could use to free or close that file I've written.
-- Jim Lowary