c# - Thread with while (true) loop exits somehow -


i have thread supposed run continuously in program , parse incoming serial data collection of sensors.

//initialized global variable system.threading.thread processthread = new system.threading.thread(processserialdata);  //this gets called when press start button processthread.start();   private void processserialdata() {     while (true)     {         //do whole bunch of parsing stuff     }     int howdidyougethere = 0; } 

how possible program reaching "int howdidyougethere = 0" line??

full code can found here:

    /// <summary>     /// processserialdata thread used continue testing connection controller,     /// process messages in incoming message queue (actually linked list),      /// , sends new messages updated data.     /// </summary>     /// <param name="sender"></param>     /// <param name="e"></param>     private void processserialdata()     {         while (true)         {             updateahtextbox(test.amphoursout.tostring());              if (!relayboard.openconn())             {                 messagebox.show("connection controller has been lost.");                 testinterrupted = "lost connection. time = " + test.duration;                 updatestatustext(false);                 shuterdown();             }              /////////////////////////////////////////////////////             if (incomingdata.count > 0)             {                 string dataline = "";                 try                 {                     dataline = incomingdata.first();                     updateparseddatatextbox(dataline + "\r\n");                 }                 catch (system.invalidoperationexception emai)                 {                     break; //data hasn't come in yet, time runs next.                 }                  incomingdata.removefirst();                  if (dataline.contains("get")) // sensor values (analog/temp/digital) has come in                 {                     if (dataline.contains("getanalog")) // analog value has come in                     {                         int index = dataline.indexof("ch");                         int pin = (int)char.getnumericvalue(dataline[index + 2]);                          double value = 0;                         int datalinelength = dataline.length;                         if (datalinelength > 13) // value appended end of line                         {                             try                             {                                 value = convert.todouble(dataline.substring(13));                             }                             catch // can't convert double                             {                                 int index2 = dataline.indexof("ch", 3);                                 if (index2 != -1) // there happen 2 sets of commands stuck 1                                 {                                     string secondhalf = dataline.substring(index2);                                     incomingdata.addfirst(secondhalf);                                 }                             }                         }                         else // value on next line                         {                             try                             {                                 value = convert.todouble(incomingdata.first());                                 incomingdata.removefirst();                             }                             catch // can't convert double                             {                                 messagebox.show("error occured: " + dataline);                             }                         }                         switch (pin)                         {                             case 1:                                 readvoltage(value);                                 break;                             case 2:                                 readamperage(value);                                 break;                         }                     }                     else if (dataline.contains("gettemp")) // received reply temperature data                     {                         int index = dataline.indexof("ch");                         int pin = (int)char.getnumericvalue(dataline[index + 2]); // using index of ch, retrieve pin message coming                          double value = 0;                         int datalinelength = dataline.length;                         if (datalinelength > 11) // value appended end of line                         {                             try                             {                                 value = convert.todouble(dataline.substring(11));                             }                             catch // can't convert double                             {                                 int index2 = dataline.indexof("ch", 3);                                 if (index2 != -1) // there happen 2 sets of commands stuck 1                                 {                                     string secondhalf = dataline.substring(index2);                                     incomingdata.addfirst(secondhalf);                                 }                             }                         }                         else // value on next line                         {                             value = convert.todouble(incomingdata.first());                             incomingdata.removefirst();                         }                         readtemperature(pin, value);                     }                     else // must ch3.get                     {                         int index = dataline.indexof("ch");                         int pin = (int)char.getnumericvalue(dataline[index + 2]); // using index of ch, retrieve pin message coming                          if (pin == 3) // care if it's pin 3 (bms), otherwise it's mistake                         {                             double value = 0;                             int datalinelength = dataline.length;                             if (datalinelength > 7) // value appended end of line                             {                                 try                                 {                                     value = convert.todouble(dataline.substring(7));                                 }                                 catch // can't convert double                                 {                                     int index2 = dataline.indexof("ch", 3);                                     if (index2 != -1) // there happen 2 sets of commands stuck 1                                     {                                         string secondhalf = dataline.substring(index2);                                         incomingdata.addfirst(secondhalf);                                     }                                 }                             }                             else // value on next line                             {                                 value = convert.todouble(incomingdata.first());                                 incomingdata.removefirst();                             }                             readbms(value);                         }                     }                 }                 else if (dataline.contains("rel")) // received reply relay turning on or off.                 {                     if (dataline.contains("rels")) // relays turning on/off                     {                         if (dataline.contains("on"))                         {                             (int pin = 1; pin <= 4; pin++)                             {                                 test.contactors[pin] = true;                             }                         }                         else // "off"                         {                             (int pin = 1; pin <= 4; pin++)                             {                                 test.contactors[pin] = false;                             }                         }                     }                     else // single relay turning on/off                     {                         int index = dataline.indexof("rel");                         int pin = (int)char.getnumericvalue(dataline[index + 3]);                          if (dataline.contains("on"))                         {                             test.contactors[pin] = true;                         }                         else if (dataline.contains("off"))                         {                             test.contactors[pin] = false;                         }                         else if (dataline.contains("get"))                         {                             if (convert.toint32(incomingdata.first()) == 1)                                 test.contactors[pin] = true;                             else                                 test.contactors[pin] = false;                             incomingdata.removefirst();                         }                     }                 }             }             /////////////////////////////////////////////////////              // want more data if we're done processing current data, otherwise we're stuck , processing heavily delayed.             if (istestrunning && incomingdata.count < 3)             {                 //read & output v, a, bms state                 sendtocontroller("ch1.getanalog"); // voltage                 sendtocontroller("ch2.getanalog"); // amperage                 sendtocontroller("ch3.get"); // bms state                  //read & output temperature                 sendtocontroller("ch4.gettemp"); // temperature                 sendtocontroller("ch5.gettemp");                  string lines = "ah out: " + test.amphoursout + ", voltage: " + test.voltage +                     ", amperage: " + test.amperage + ", cell temperature: " + test.tempbattery +                     ", load temperature: " + test.tempload;                 writetolog(lines);             }         }         int howdidyougethere = 0;     } 

the break (ignoring inside nested switch) breaks out of while loop.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -