Hello, this is an odd problem,

I have a method that goes through a list (in a foreach cycle) and writes every string found in the list to a text file, each string in a new line (then a blank line) then the next string.

The list contains 106 strings, if I run the program everything goes fine, I can even run it in debug mode and see how the foreach iterates through all the strings in the list and writes the line.

The problem is that when I open the new text file everything seems fine except that it truncates sometimes in line 90, or 95 but it never shows the other strings. The final string that it shows is always truncated

FOr instance, all strings are HelloWorld, the last string is HelloW

What can I do to write all the lines, why does it stop writting them even if the debug mode shows that writes all the lines.

Thanks in advance.

Hi, thanks that did the trick, anyway I searched the StreamWriter.Flush() method but could not understand why I need it, why with StreamWriter.WriteLine() it writes some lines but not all?

All file based streams have a 4k buffer that gets written when the OS feels like it, or it becomes full. Flush() forces the OS to clear the buffer.