title: TCP Client data recieved using event handler
body: <p>I am working with a TCP client to learn how to use the TCPSocket function in VS2010 C#. I can call the read() function to read the data. That part all works. What I am not understanding is how to set the client up to listen to the stream and post the incoming data to a text box without calling the function manually or using a timer. I would like to have this handled with an event handler, but at this point I have just completely confused myself and now I need some guidance. </p>
  
  <p>I am using a client sample I found on MSDN to help me understand how the function works to do a basic read. </p>
  
  <pre><code>private static void Receive(Socket client) {
      try {
          // Create the state object.
          StateObject state = new StateObject();
          state.workSocket = client;
  
          // Begin receiving the data from the remote device.
          client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
              new AsyncCallback(ReceiveCallback), state);
      } catch (Exception e) {
          Console.WriteLine(e.ToString());
      }
  }
  </code></pre>
  
  <p>On an other stackoverflow post I found Matt Davis provided an <a href="https://stackoverflow.com/questions/20694062/can-a-tcp-c-sharp-client-receive-and-send-continuously-consecutively-without-sle">example</a> of using a public event</p>
  
  <pre><code>public event EventHandler&lt;DataRecivedEventArgs&gt; DataRecieved;
  </code></pre>
  
  <p>However when I tried it, the "DataRecivedEventArgs" is not a recognized function of visual studio.</p>
  
  <p>Can someone help explain to me how to use TCPclient to consistently listen for data and call a function when some data is received?</p>