FeliceM
FeliceM

Reputation: 4199

Visual Studio debug break points freezing app

I have added a couple of break points in my code to monitor the value of two variables when reached. The application basically receives a stream of data at 9600 baud from serial port generated by a micro controller working at 500 Hz and has to filter the messages according to certain rules "if" and "if else" to strip out header characters and address them to other variables for calculation usage. Here is the code:

 class Stripper
{
 public  void  Distri (string inComing, out string param1, out string param2, out string param3, out string param4)
    {
        string currentRes="";
        string currentMot = "";
        string temperature="";
        string numRPM="";
        string f = inComing;
        if (inComing.Length < 6)
        {
            f = ">123456<";
        }
        char firstChar = f[0];
        char lastChar = f[f.Length - 2];
        bool test1 =(firstChar.Equals('>'));
        bool test2 =(lastChar.Equals('<'));
        int messLenght = f.Length;

        try
        {
            if (test1 == true && test2 == true && messLenght <= 10)
            {
                f = f.Replace("<", "");
                f = f.Replace(">", "");

                if (f[0] == 'I')
                {
                    string _currentRes = f;
                    _currentRes = _currentRes.Replace("I", "");
                    currentRes = _currentRes;
                }

                else if (f[0] == 'M')
                {
                    string _currentMot = f;
                    _currentMot = _currentMot.Replace("M", "");
                    currentMot = _currentMot;
                }

                else if (f[0] == 'T')
                {
                    string _temperature = f;
                    _temperature = _temperature.Replace("T", "");
                    temperature = _temperature;
                }
                else if (f[0] == 'N')
                {
                    string _numRPM = f;
                    _numRPM = _numRPM.Replace("N", "");
                    numRPM = _numRPM;
                }

                else
                { }
            }

            else
            { }
        }
        catch (System.Exception)
        {

            throw;
        }

        param1 = currentRes;
        param2 = temperature;
        param3 = numRPM;
        param4 = currentMot;

        }
       }
      }

The problem I am facing is quite strange and at some point I was completely lost. Basically with the break points active on variable "f" and "inComing" the app was immediately unresponsive and, to make it work, I had to reduce the speed of the stream from serial to 1/100 introducing delays. Without the break points the app can take the full stream of data without any problem. May be this experience could also help other people in similar situations. Looks like the break points are slowing down the process quite dramatically.I do not think it has something to do with the pc I am using being this a monster with 16 Gb RAM and 2.4 Ghz processor i5. I am wondering why this is happening and if there a way to avoid such problem rather than not using the break points?

Upvotes: 0

Views: 303

Answers (1)

WiiMaxx
WiiMaxx

Reputation: 5420

I found it on an quick search Debug.WriteLine()
is the thing to write to your VS Output Window

so you will be able to get your realtime values

see also this link

Upvotes: 1

Related Questions