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
Loading
Juan Antonio 0Posted Jan 23, 2006, 9:07 AM
Best regards
(Sorry my english)
Brian ManlovePosted Jan 19, 2006, 5:46 PM
Brian ManlovePosted Jan 19, 2006, 5:43 PM
Juan Antonio 0Posted Jan 19, 2006, 3:37 PM
Best regards
AnttiPosted Jan 19, 2006, 1:17 PM
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();
}