The snippet of code was just supposed to write a string into a text file called \"all_results.txt\". I had errors implementing in File.WriteAllText. After searching the net
use a utility like filemon to check which processes are using the file.
UPDATE: From what i read Process monitor is very much similar to filemon. from either of these tools you can find which process accessed your file at what point. you can add a filter for your file before you start monitoring.
the other thing you could try is to get a lock on the file if it exists.
Maybe the file is accessed by virus scanner or windows indexing service?
Pedro:
As others have stated, opening and closing the file repeatedly might be the issue. One solution not mentioned is to keep the file open for the duration of the processing. Once complete, the file can be closed.
Or, alternatively, collect your text in a StringBuilder or some other in-memory text storage and then dump the text to the file once the loop finishes.
Dont call Dispose() and Close() on the FileStream and StreamWriter, this will be handled automatically by the using-clause.
Try writing the file to another directory outside of the debug folder.
Just a "wild shot" - does it help if you place the file in a more predictable location like 'c:\all_results.txt'?