.net from application Thread Broken error

İ have been trying to make application to reed data from serial(baudrate 9600) and write to a text box than write the same data to graph but it wont work. it either doesn’t do anything or the application froze until my RAM runs out and from what i can see moment i connect to my arduino(i checked with arduino İDE it sends the data correctly) my ram usage goes from 32-50 to 1gb and internet doesn’t have any solution i couldn’t even find the same problem

here’s my code

`using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Security.Cryptography.X509Certificates;
using System.Data.Common;
using System.Windows.Forms.DataVisualization.Charting;
using System.Web.UI.DataVisualization.Charting;


namespace ArduinoSerial_Teknofest_
{
    public partial class ArduinoSerial : Form
    {

        #region public veriables
        public class Globals
        {
            public static Boolean Connected = false;
            public static Boolean İfDisconnected = false;
        }

        /// To write information to console 
        public void WriteToConsole(string messege, string TextColor)
        {
            ConsoleLogs.SelectionColor = Color.FromName(TextColor);
            ConsoleLogs.SelectedText += "/// " + messege + Environment.NewLine;
        }



        #endregion

        public ArduinoSerial()
        {
            InitializeComponent();
            // Get a list of serial port names.

            PortsCB.Items.AddRange(SerialPort.GetPortNames());
            //DataCharts.Series
        }

        private void ArduinoSerial_Load(object sender, EventArgs e)
        { /*
            //Get the resulation of screen
            System.Drawing.Rectangle ScreenResulation = Screen.PrimaryScreen.WorkingArea;

            //Set size of form to 50% of screen size
            this.Size = new System.Drawing.Size(Convert.ToInt32(0.5 * ScreenResulation.Width),Convert.ToInt32(0.5 * ScreenResulation.Height));

            this.Location = new System.Drawing.Point(10, 10);
          */
        }

        public void Scan_click(object sender, EventArgs e)
        {
            // Get a list of serial port names.
            string[] ports = SerialPort.GetPortNames();

            PortsCB.Items.Clear();
            PortsCB.Items.AddRange(ports);
            WriteToConsole("Found PORTS = ", "Green");
            foreach (string port in ports)
            {
                WriteToConsole(port, "Green");
            }
        }
        public void ConnectButton_Click(object sender, EventArgs e)
        {
           string SelectedBaudRate = BaudRateCB.Text;
           string SelectedPort = PortsCB.Text;
            if (Device.IsOpen == false)
            {
                ///Try to open the port if cant give an error
                try
                {
                    ///Get user info
                    Device.BaudRate = int.Parse(SelectedBaudRate);
                    Device.PortName = SelectedPort;
                    Device.Open();
                    ///Check if the port open, if it is disable user input bloccks
                    if (Device.IsOpen == true)
                    {
                        ConnectButton.Text = "Disconnect";
                        BaudRateCB.Enabled = false;
                        PortsCB.Enabled = false;
                        DataMenu.Enabled = true;
                        WriteToConsole("Connected", "green");
                        Device.Write("get/device/info");
                        
                    }
                }
                catch (System.IO.IOException) { WriteToConsole("Something went wrong", "red"); }
                ///if post is used by other program output a error
                catch (System.UnauthorizedAccessException)
                {
                    WriteToConsole("port busy", "red");
                    Device.Close();
                }
                ///if port is allready open output an error
                catch (System.InvalidOperationException)
                {
                    WriteToConsole("Port is already open", "red");
                    Device.Close();
                }
                catch (System.ArgumentNullException)
                {
                    if (PortsCB.Text == "" && BaudRateCB.Text == "") { WriteToConsole("Please select a port and baudrate", "red"); }
                    else if (PortsCB.Text == "") { WriteToConsole("Please select a port", "red"); }
                    else if (BaudRateCB.Text == "") { WriteToConsole("Please select a baudrate", "red"); }
                }
                catch (System.ArgumentException)
                {
                    if (PortsCB.Text == "" && BaudRateCB.Text == "") { WriteToConsole("Please select a port and baudrate", "red"); }
                    else if (PortsCB.Text == "") { WriteToConsole("Please select a port", "red"); }
                    else if (BaudRateCB.Text == "") { WriteToConsole("Please select a baudrate", "red"); }
                }
                catch (System.FormatException)
                {
                    if (PortsCB.Text == "" && BaudRateCB.Text == "") { WriteToConsole("Please select a port and baudrate", "red"); }
                    else if (PortsCB.Text == "") { WriteToConsole("Please select a port", "red"); }
                    else if (BaudRateCB.Text == "") { WriteToConsole("Please select a baudrate", "red"); }
                }
            }
            else if (Device.IsOpen == true)
            {
                WriteToConsole("Disconnected!!", "green");
                Device.Close();
                ConnectButton.Text = "Connect";
                BaudRateCB.Enabled = true; ;
                PortsCB.Enabled = true;
                DataMenu.Enabled = false;
                ConsoleLogs.Clear();
                PositionGraph.Series["gyroX"].Points.Clear();
                PositionGraph.Series["gyroY"].Points.Clear();
                ChartCounter = 0;
            }
        }



        string recivedData;


        //List<double> time = new List<double>();
        void Parachute_Status(string data)
        {
            int intData = int.Parse(data);
            switch (intData)
            {
                case 1:
                    parachute1_Status.Text = "Not triggered";
                    parachute2_Status.Text = "Not triggered";
                    break;
                case 2:
                    parachute1_Status.Text = "Triggered";
                    parachute2_Status.Text = "Not triggered";
                    break;
                case 3:
                    parachute1_Status.Text = "Not triggered";
                    parachute2_Status.Text = "Triggered";
                    break;
                case 4:
                    parachute1_Status.Text = "Triggered";
                    parachute2_Status.Text = "Triggered";
                    break;
            }
        }

        private void dataRecived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {

                recivedData = Device.ReadLine();


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "hata");

            }


            this.BeginInvoke(new EventHandler(ProcessData));
        }

        int ChartCounter;
        private void gyroChart(string gyroDataX, string gyroDataY)
        {
           while (Device.IsOpen == true)
            {
                ChartCounter++;
                PositionGraph.Series["gyroX"].Points.AddXY(double.Parse(gyroDataX), ChartCounter);
                PositionGraph.Series["gyroY"].Points.AddXY(double.Parse(gyroDataY), ChartCounter);
            }
        }
        private void ProcessData(object sender, EventArgs e)
        {

            try
            {
                
                string[] splitted_data = recivedData.Split('/');
                //gyroChart(splitted_data[0], splitted_data[1]);
                WriteToConsole(recivedData, "red");
                //irtifa_Box.Text = splitted_data[0];
                //GPS_Box.Text = splitted_data[1];
                //Enlem_Box.Text = splitted_data[2];
                //Boylam_Box.Text = splitted_data[3];
                /*YGPS_Box.Text = splitted_data[4];
                YEnlem_Box.Text = splitted_data[5];
                YBoylam_Box.Text = splitted_data[6];
                KGPS_Box.Text = splitted_data[7];
                KEnlem_Box.Text = splitted_data[8];
                KBoylam_Box.Text = splitted_data[9];
                JiroskopX_Box.Text = splitted_data[0];
                JiroskopY_Box .Text = splitted_data[1];
                JiroskopZ_Box .Text = splitted_data[12];
                gyroChart(JiroskopX_Box.Text, JiroskopY_Box.Text);
                İvmeX_Box.Text = splitted_data[13];
                İvmeY_Box.Text = splitted_data[14];
                İvmeZ_Box.Text = splitted_data[15];
                Aci_Box.Text = splitted_data[16];
                CRC_Box.Text = splitted_data[17];
                Parachute_Status(splitted_data[18]);
                Heat_Box.Text = splitted_data[19]; 
                */

            }
            catch (System.IO.IOException)
            {
                WriteToConsole("error", "red");
                return;
            }
            catch (System.IndexOutOfRangeException)
            {
                WriteToConsole("error", "red");
                return;
            }
            catch (System.InvalidOperationException)
            {
                WriteToConsole("error", "red");
                return;
            }
        } //Evde dock sistemlerine bak ve arayüz gelişimi için açık sayfalara bak
    }

}

i cant give the error since i am Turkish and gives the main error in Turkish

i tried changing the baudrate but didnt work and since it was only idea i got stuck

New contributor

user25017301 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật