Question: I need recive multiple messages at client, but `ReadLineAsync()` only read first message.

```
    //Server Side
    StreamWriter StwWriter = new StreamWriter(client.GetStream())
    {
        AutoFlush = true
    };
    for (int i = 0; i < 10; i++)
    {
        StwWriter.WriteLine("test");
    }
    // Client Side
    public async void WaitMessages()
    {
        while (LoginChat.Client.Connected)
        {
            try
            {
                var reader = new StreamReader(LoginChat.Client.TcpClt.GetStream());
                var data = await reader.ReadLineAsync();
                MessageBox.Show(data);
            }
            catch (Exception ex)
            {
              MessageBox.Show(ex.ToString());  
            }
        }
    }
    WaitMessages();

```

The output only show the first message. What is wrong?

Answer: 
`StreamReader` has internal buffer, so when you do this:

```
var reader = new StreamReader(LoginChat.Client.TcpClt.GetStream());
var data = await reader.ReadLineAsync();

```

It might have read much more than one line. It's not a problem if you then continue using the same `StreamReader` instance to fetch next lines, but you just read one line then discard `StreamReader`. That means everything that was in its buffer is lost.

To fix - don't create new `StreamReader` in every loop iteration, but use one instance:

```
public async Task WaitMessages()
{
    var reader = new StreamReader(LoginChat.Client.TcpClt.GetStream());
    while (LoginChat.Client.Connected)
    {
        try
        {                
            var data = await reader.ReadLineAsync();
            MessageBox.Show(data);
        }
        catch (Exception ex)
        {
          MessageBox.Show(ex.ToString());  
        }
    }
}

```
As i Provided in comment , you need to create steam outside while loop so code should be like this , it causing problem as you are creating stream every time in you code 

```
public async Task WaitMessages()
{
    var reader = new StreamReader(LoginChat.Client.TcpClt.GetStream());
    while (LoginChat.Client.Connected)
    {
        try
        {                
            var data = await reader.ReadLineAsync();
            MessageBox.Show(data);
        }
        catch (Exception ex)
        {
          MessageBox.Show(ex.ToString());  
        }
    }
}

```