I am currently facing an issue, I have a method that I run which queries specific ports of a server and writes the results to a text file called temp.txt. Temp.txt should never have any duplicate data in – the file should be clear before the method begins, although sometimes I find that the previous instance of the method is still running (as its asynchronous) and I often get duplicate data since the other method is still writing to the file / performing the queries.
Code Snippet:
StreamWriter sw = File.AppendText("temp");
sw.WriteLine("Check1=Success");
sw.Close();
You can implement some sort of lock