The following method (image) is used to offload file data in chunks (lines).
The while loop parses 'x' lines from a file and when it reaches a certain max count, we proceed with the offload of those lines.
Once the offload is done, it goes back to the QAction and re-enters the loop with the StreamReader to offload the next 'x' lines.
So far, everything is fine as this mechanism seems to work.
The only issue is that every time we re-enter the QAction and use the StreamReader, the first line (iteration) retrieved is always incomplete.
Does anyone have any idea on why this is happening and how to fix it?
Many Thanks.
StreamReader uses an internal buffer (default size 1024) because it would not be very efficient to read one byte at a time from the source stream. When the StreamReader gets disposed at the end of the using statement, that internal buffer will contain unprocessed bytes that have already been read from the underlying stream and they will be lost. When you later create a new StreamReader to continue reading from the underlying stream, it will continue from wherever the previous StreamReader left off.
Where you now only store _fileStream inbetween QAction invocations, you can simply also store your StreamReader and keep using the same instance to continue reading lines from.