Code:
String tempFile = Path.GetTempFileName(), read = ""; TextReader pending = new StreamReader("c:\\pending.txt"); TextWriter temp = new StreamWriter(tempFile); read = pending.ReadLine(); while ((read = pending.ReadLine()) != null) { temp.WriteLine(read); } pending.Close(); temp.Close(); File.Delete("c:\\pending.txt"); File.Move(tempFile, "c:\\pending.txt");
The pending.txt file is created when the program starts if it doesn't exist. This code deletes the first line of the file. When I debug the code, I notice that the
File.Move(tempFile, "c:\\pending.txt");
locks the file and I cannot write to it anymore.