title: Serial port listening through windows services in C#
body: <p>I have created a windows service to listen the serial port inputs,below is my code but Im getting an error like missing assembly, I googled it but few article says to add <code>System.WIndows.Forms</code> Namespace,Even i added that Im getting the same error </p>
  
  <blockquote>
    <p>Error 1   'VisionSystemService.VisionSystemService' does not contain a
    definition for 'BeginInvoke' and no extension method 'BeginInvoke'
    accepting a first argument of type
    'VisionSystemService.VisionSystemService' could be found (are you
    missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <pre><code> public partial class VisionSystemService : ServiceBase
      {
          SerialPort _SerialPort;
          private delegate void SetTextDeleg(string text);
  
          public VisionSystemService()
          {
              InitializeComponent();
              _SerialPort = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
              _SerialPort.Handshake = Handshake.None;
              _SerialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
              _SerialPort.ReadTimeout = 500;
              _SerialPort.WriteTimeout = 500;
              _SerialPort.Open();
  
          }
          void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
          {
              Thread.Sleep(500);
  
              string data = _SerialPort.ReadExisting();
              this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
          }
  
          protected override void OnStart(string[] args)
          {
  
  
  
  
          }
  
  
          private void si_DataReceived(string data)
          {
  
          }
  
          protected override void OnStop()
          {
  
          }
      }
  </code></pre>