title: Streaming data between C# applications
body: <p>I'm trying to share data between two applications: the first gets the data continuously from a sensor, all I need to do is to transmit these data while I'm receiving them to another (WPF) application (and draw a graph).</p>
  
  <p>The data is received through an EventHandler, and then it's transmitted through a socket, like this:</p>
  
  <pre><code>    static TcpClient client = new TcpClient("localhost", 8181);
      static double w, dba;
  
      static void Write()
      {
          try
          {
              Stream s = client.GetStream();
              StreamReader sr = new StreamReader(s);
              StreamWriter sw = new StreamWriter(s);
              sw.AutoFlush = true;
              while (true)
              {
                  String line = "W:" + w + "DB/A:" + dba;
                  sw.Write(line);
                  Console.WriteLine(sr.ReadLine());
              }
              s.Close();
          }
          finally
          {
              client.Close();
          }
      }
  </code></pre>
  
  <p>The thing is, do I need to put it in a separate Thread? (As I tried to, unsuccessfully) Because like this, while the eventHandler keeps being triggered and producing data (storing it into the two variables), the sw seems unable to proceed.</p>
  
  <p>Sorry if the question is a bit vague, it's my first attempt with a distributed app so I'm a bit confused as well.. any advice or help would be very appreciated! </p>
  
  <p>TIA</p>