Greetings good people,
I have a rather strange issue (for me at least) regarding WebClient and reading data for a continuous data stream and I’m not really sure where the issue is. The stream receives data almost as expected, except the last row. But when new data arrives, the unprinted row prints above the new data.
For example, a set of lines is retreived and it could look like this:
<batch name="home">
<event id="1"/>
And when the next set arrives, it contains the missing end block from the above set:
</batch>
<batch name="home">
<event id="2"/>
The code presented is simplified, but hopefully is enough for getting a clearer picture.
WebClient _client = new WebClient();
_client.OpenReadCompleted += (sender, args) =>
{
using (var reader = new StreamReader(args.Result))
{
while (!reader.EndOfStream)
{
Console.WriteLine(reader.ReadLine());
}
}
};
_client.OpenReadAsync(new Uri("localhost:1234/testdata?keep=true"));
In this setup the reader.EndOfStream never gets to true because the stream doesn't end. Anyone have a suggestion on how to retrieve the last line? Am I missing something or could the fault be with the API?
Kind regards :)