简体   繁体   English

C#应用程序在20-30分钟后会变慢吗?

[英]C# application slows Down after 20-30 mins?

I have c# application which reads data from serial port. 我有C#应用程序,它从串行端口读取数据。 I have put serial read handler in timer with interval 1 second , because data coming every 1 second on timer I calling 我将串行读取处理程序放入间隔为1秒的计时器中,因为我调用的计时器中的数据每隔1秒就会出现一次

delegate void SetTextCallback(string text);
ReceivedText(serialPort1.ReadExisting());

I also showing received data in richtextbox just to check it getting proper data or not. 我还在richtextbox中显示接收到的数据,只是为了检查它是否获取正确的数据。 But after 15-20 mins application slows down wont even respond. 但是在15到20分钟后,应用程序变慢甚至都不会响应。

 private void ReceivedText(string text)
 {
        if (this.rtbReceived.InvokeRequired)
        {
            SetTextCallback x = new SetTextCallback(ReceivedText);
            this.Invoke(x, new object[] { (text) });
        }
        else
        {
            this.rtbReceived.Text += text;
            serialdata = text;
            if (serialdata.Length > 0 &&
                serialdata.Length < 42 &&
                serialdata.Contains("#") ||
                serialdata.StartsWith(" #"))
            {
                serialdata.Trim();
                splitdata = serialdata.Split(' ');

                try
                {
                    txtBathTemp.Text = splitdata[3];
                    txtBaroPressure.Text = splitdata[4];

                    double stemp = double.Parse(splitdata[5]);

                    txtSampleTemp.Text = (Math.Round(stemp, 2)).ToString();
                }
                catch (Exception EX)
                { 
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }

There is a chance that this.rtbReceived.Text grows up after some time. 一段时间后, this.rtbReceived.Text会长大。 Even if it doesn't use huge amount of memory, constantly manipulating String is not efficent. 即使不使用大量内存,不断操作String也不起作用。 Have you considered using StringBuilder instead? 您是否考虑过使用StringBuilder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 30-40分钟后性能下降c# - performance degradation after 30-40 mins c# asp.net-core2.0 用户在 20-30 分钟后自动注销 - asp.net-core2.0 user auto logoff after 20-30 min 当程序创建大量对象时,C# 应用程序 CPU 性能急剧下降 - C# application CPU performance drastically slows down when program creates a high number of objects 经过特定数量的迭代后,AutoCAD COM Application的速度降低 - AutoCAD COM Application slows down after a specific amount of iterations 没有内存泄漏或错误,但是我的代码以指数方式减慢了C# - No memory leaks or errors but my code slows down exponentially C# 为什么要花费近20到30秒的时间来更改Project Settings…&gt; Quality的质量,使用脚本? - Why it's taking almost 20-30 seconds to change the quality value of the Project Settings… > Quality using script? 将 DateTime 1/20/2022 8:48:30 PM 转换为 20/01/2022 8:48:30 PM C# - Convert DateTime 1/20/2022 8:48:30 PM to 20/01/2022 8:48:30 PM C# 长时间运行的应用程序变慢 - Long running application slows down Mahapps减慢了WPF应用程序的速度 - Mahapps slows down WPF application 达到内存限制会降低.Net应用程序的速度 - Hitting a memory limit slows down the .Net application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM