'Serial port listening through windows services in C#

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 System.WIndows.Forms Namespace,Even i added that Im getting the same error

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?)

 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()
        {

        }
    }


Solution 1:[1]

Your getting this error because neither your VisionSystemService class or ServiceBase have a method called BeginInvoke. I recommend to just invoke your delegate.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yunnosch