title: Picture not displayed when readasync
body: <p>I do my first Xamarin Cross Platform App.</p>
  
  <p>I´m trying to display a picture , which comes from a TCP-Server, written by me. </p>
  
  <p>At first I tried to reload the picture everytime the Site is requested. But because of reading the stream synchronously , the site needs a long time to load and is additionally blocking the UI. So I tried to read the networkstream asyncronously. But so I don´t get the picture displayed. Also I´m not sure, if the reveived Data is complete.</p>
  
  <pre><code>public static async Task&lt;bool&gt; ReceivePicture(string sTCP, int iPort, Byte[] bData)
      {
          TcpClient client = new TcpClient   // Creates a TCP Client
          {
              ReceiveTimeout = 800,
              SendTimeout = 800
          };
          client = new TcpClient(sTCP, iPort); //Trys to Connect
  
          await client.ConnectAsync(sTCP, iPort);
          if (!client.Connected)
              return false;
  
          NetworkStream serverStream = client.GetStream();
  
          string sSend = "DATA_PICTURE";
  
          byte[] outStream = Encoding.UTF8.GetBytes(sSend);
          serverStream.Write(outStream, 0, outStream.Length);
          serverStream.Flush();
  
          byte[] inStream = new byte[32];
          int j = 0;
  
          var ack = await serverStream.ReadAsync(inStream, j, inStream.Length);
  
          UTF8Encoding encoder = new UTF8Encoding();
  
          string sMessage = encoder.GetString(inStream, 0, ack);
  
          string[] words = sMessage.Split(';');
          Int32.TryParse(words[1], out int iPicSize);
  
          sSend = "OK";
          outStream = Encoding.UTF8.GetBytes(sSend);
          serverStream.Write(outStream, 0, outStream.Length);
          serverStream.Flush();
  
          var encoding = Encoding.UTF8;
          var i = 0;
          byte[] inStreamPic = new byte[iPicSize];
          var sb = new StringBuilder();
  
          //while (!serverStream.DataAvailable)
          //{
          //}
  
          //while (serverStream.DataAvailable)
          //{
          //    serverStream.Read(inStreamPic, j, 1);
          //    j++;
          //}
  
          while ((i = await serverStream.ReadAsync(inStreamPic, 0, inStreamPic.Length)) != 0)
          {
              sb.Append(encoding.GetString(inStreamPic, 0, i));
              if (!serverStream.DataAvailable) break;
          }
  
          img.Source = ImageSource.FromStream(() =&gt; new MemoryStream(inStreamPic));
          bData = inStreamPic;
  
          //var sFileName = Path.Combine(App.FolderPath, "Screen.png");
          //File.WriteAllBytes(sFileName, bData);
          //ImageConverter ic = new ImageConverter();
  
  
          //File.WriteAllBytes(sFileName, bData);
          //sFileName = img. ;
          client.GetStream().Close();
          client.Close();
          return true;
      }
  </code></pre>