Hello!
I have one program that modifies one file. After this program finalizes is started a .bat file for renaming the file that has been modified by the program. Some times I get the message "The process cannot access the file because it is being used by used by another program" The program that has modified the file has not free the file yet. I want to make another program in C# for waiting until the file be free but I didn't find any function within System.IO for doing this task. Is there any way to test this condition into C#?
Best regards
Waiting for a locked file
5 Answers
Know the answer? Post it. Somebody with the same question will find it here.
AnttiRank #9,295 · 208 pointsPosted Jan 19, 2006, 8:17 AM EST
Did You remember to close the file stream that modified the file? All streams have a Close method, that frees the system resources associaced by the stream.
TextWriter file = null; try { file = new StreamWriter("filename.txt"); //write here file.WriteLine("Contents of the file"); } catch(Exception ex) { //handle exceptions here } finally { //close file here, not in try block!! file.Close(); }Juan Antonio 011 pointsPosted Jan 19, 2006, 10:37 AM EST
Best regards
Brian Manlove6 pointsPosted Jan 19, 2006, 12:43 PM EST
Brian Manlove6 pointsPosted Jan 19, 2006, 12:46 PM EST
Juan Antonio 011 pointsPosted Jan 23, 2006, 4:07 AM EST
Best regards
(Sorry my english)