Quantcast
Channel: File locks when using file.move in c#...how can I stop or fix this - Stack Overflow
Viewing all articles
Browse latest Browse all 3

File locks when using file.move in c#...how can I stop or fix this

$
0
0

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.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>