title: How can I make this a never ending loop with time out every 1 successful process
body: <p>This is my code which parses a string coming from a database. The database has around 50 data strings and continuously grows every 5 seconds.</p>
  
  <p>I want this code to enter a never ending loop so if new data arrives and the table is empty it will immediately parse it.</p>
  
  <p>I'm only asking for possible suggestion on how to make this code a never ending looping processor.</p>
  
  <p>Code below</p>
  
  <pre><code>private void btnActiveStart_Click(object sender, EventArgs e)
  {
      string connetionString = null;
      SqlConnection cnn;
      connetionString = "Data Source=SAMPLE12345;Initial Catalog=SAMPLE_TABLE;User ID=sa;Password=str0ngp@ssw0rd;MultipleActiveResultSets=True";
      cnn = new SqlConnection(connetionString);
      cnn.Open();
      string sqlquery = "SELECT top 1 SMSMSG,SMSDT FROM GPRSIN WHERE isHEX = '0'";
  
      SqlCommand command = new SqlCommand(sqlquery, cnn);
  
      SqlDataReader sdr = command.ExecuteReader();
  
      while (sdr.Read())
      {
          string input = sdr["SMSMSG"].ToString();
          string smsdt = sdr["SMSDT"].ToString();
          int s = input.Length;
          if (s == 105)
          {
              string account       = input.Substring(0, 15);
              txtbxImeiActive.Text = account;                       //ACCOUNT
              DateTime now         = DateTime.Now;              
              String finnow        = now.ToString("yyyy-MM-dd HH:mm:ss.fff");
              txtbxDateTimeStampFast.Text = finnow.ToString();      //DATETIME
              //Convert date START
              string datetime      = input.Substring(65, 12);
              string hour          = datetime.Substring(0, 2);
              string minutes       = datetime.Substring(2, 2);
              string seconds       = datetime.Substring(4, 2);
              string day           = datetime.Substring(6, 2);
              string month         = datetime.Substring(8, 2);
              string year          = datetime.Substring(10, 2);
              string strdate       = "20" + year + "-" + month + "-" + day + " ";
              string strtime       = hour + ":" + minutes + ":" + seconds + ".000";
              string findatetime   = strdate + strtime;
              DateTime gpsdatefast = Convert.ToDateTime(strdate);
              String fingpsdatefast= gpsdatefast.ToString("yyyy-MM-dd HH:mm:ss.fff");
              DateTime gpstimesfast = Convert.ToDateTime(strtime);
              String fingpstimefast = gpstimesfast.ToString("HH:mm:ss");
              //Convert date END
              txtbxGpsDateFast.Text = fingpsdatefast.ToString();    //GPSDATE
              txtbxGpsTimeFast.Text = fingpstimefast.ToString();    //GPSTIME
              DateTime trxdatefast  = Convert.ToDateTime(smsdt);
              String fintrxdatefast = trxdatefast.ToString("yyyy-MM-dd 00:00:00.000");
              txtbxTrxDateFast.Text = fintrxdatefast;
  
              DateTime trxtimefast  = Convert.ToDateTime(smsdt);
              String fintrxtimefast = trxtimefast.ToString("HH:mm:ss");
              txtbxTrxTimeFast.Text = fintrxtimefast;
  
              DateTime philtime     = Convert.ToDateTime(findatetime).AddHours(8);
              String finphiltime    = philtime.ToString("yyyy-MM-dd HH:mm:ss.fff");
              txtbxPhilTimeFast.Text= finphiltime;
  
              //Convert DMS format to decimal (Degrees and fragment minutes) START LONG
              string deglong        = input.Substring(35, 10);
              string degreeslong    = deglong.Substring(0, 3);
              decimal degfin2       = decimal.Parse(degreeslong);
              string minuteslong    = deglong.Substring(3, 6);
              decimal minfin2       = decimal.Parse(minuteslong);
              decimal resminlong    = minfin2 / 60;
              decimal longresult    = degfin2 + resminlong;
  
              string gettlong = longresult.ToString();
              string longresultcut = gettlong.Substring(0, 7);
              decimal tlongcut = decimal.Parse(longresultcut);
              //Convert DMS format to decimal (Degrees and fragment minutes) START LONG
              txtbxLongFast.Text    = Math.Round(longresult, 6).ToString();
              txtbxTlong.Text = tlongcut.ToString();
  
              //Convert DMS format to decimal (Degrees and fragment minutes) START LAT
              string deglat         = input.Substring(25, 9);
              string degreeslat     = deglat.Substring(0, 2);
              decimal degfin1       = decimal.Parse(degreeslat);
              string minuteslat     = deglat.Substring(2, 6);
              decimal minfin1       = decimal.Parse(minuteslat);
              decimal resminlat     = minfin1 / 60;
              decimal latresult     = degfin1 + resminlat;
              string gettlat        = latresult.ToString();
              string latresultcut = gettlat.Substring(0, 6);
              decimal tlatcut      = decimal.Parse(latresultcut);
              //Convert DMS format to decimal (Degrees and fragment minutes) END  LAT
              txtbxLatFast.Text     = Math.Round(latresult, 6).ToString();
              txtbxTlat.Text = tlatcut.ToString();
  
  
              string tlocquery = "SELECT LAC,CID,LONG,LAT,STREET,MUNICIPAL FROM TRIANGULATION WHERE lat LIKE " + "'%" + tlatcut.ToString() + "%' AND long LIKE '%" + tlongcut.ToString() + "%'";
              //MessageBox.Show(platequery);
              SqlCommand commandtloc = new SqlCommand(tlocquery, cnn);
              SqlDataReader sdrtloc = commandtloc.ExecuteReader();
              while (sdrtloc.Read())
              {
                  string Tlong = sdrtloc["LONG"].ToString();
                  txtbxTlong.Text = Tlong.ToString();
                  string Tlat = sdrtloc["LAT"].ToString();
                  txtbxTlat.Text = Tlat.ToString();
  
                  string Lac = sdrtloc["LAC"].ToString();
                  txtbxLac.Text = Lac.ToString();
                  string Cid = sdrtloc["CID"].ToString();
                  txtbxCid.Text = Cid.ToString();
  
                  string Street = sdrtloc["STREET"].ToString();
                  string Municipal = sdrtloc["MUNICIPAL"].ToString();
                  txtbxTloc.Text = Street.ToString() + "," + Municipal.ToString();
              }
              string speed = input.Substring(46, 5);
              txtbxSpeedFast.Text = speed;
              string platequery = "SELECT plateno FROM ACCOUNT WHERE senderno =" + "'" + account + "'";
              //MessageBox.Show(platequery);
              SqlCommand commandplate = new SqlCommand(platequery, cnn);
              SqlDataReader sdrplate = commandplate.ExecuteReader();
              while (sdrplate.Read())
              {
                  string plate = sdrplate["plateno"].ToString();
                  txtbxActivePlate.Text = plate.ToString();
              }
  
              string locquery = "SELECT NAME,MUNICIPALI FROM ROAD WHERE lat LIKE " + "'%" + tlatcut.ToString() + "%' AND long LIKE '%" + tlongcut.ToString() + "%'";
              //MessageBox.Show(platequery);
              SqlCommand commandloc = new SqlCommand(locquery, cnn);
              SqlDataReader sdrloc = commandloc.ExecuteReader();
              while (sdrloc.Read())
              {
                  string name = sdrloc["NAME"].ToString();
                  string municipali = sdrloc["MUNICIPALI"].ToString();
                  txtbxLocation.Text = name.ToString() + "," + municipali.ToString();
              }
              string engine = input.Substring(21, 1);
              if (engine == "6" || engine == "2")
              {
                  txtbxEngineFast.Text = "ON";
              }
              else if (engine == "4" || engine == "0")
              {
                  txtbxEngineFast.Text = "OFF";
              }
              if (speed == "000.0")
              {
                  txtbxRemarks.Text = "Stopped";
              }
              else
              {
                  txtbxRemarks.Text = "Running";
              }
              string alert1 = input.Substring(20, 1);
              txtbxEvents.Text = alert1;
              string odometer = input.Substring(91, 6);
              //Convert hex to decimal and compute Odometer START
              int kmrun = Convert.ToInt32(odometer, 16);
              double kmfin = kmrun / 1000 * 1.852;
              //Convert hex to decimal and compute Odometer END
  
              txtbxOdometerActive.Text = kmfin.ToString();
              if (alert1 == "2")
              {
                  txtbxAlertActive.Text = "CIRCUIT CUT-OFF";
              }
              else if (alert1 == "4")
              {
                  txtbxAlertActive.Text = "Over the speed limit";
              }
              else if (alert1 == "6")
              {
                  txtbxAlertActive.Text = "Over the speed limit and Circuit Cut-off";
              }
              else if (alert1 == "0")
              {
  
                  if (engine == "1")
                  {
                      txtbxAlertActive.Text = "Panic Button";
                  }
                  else if (engine == "3" || engine == "7")
                  {
                      txtbxAlertActive.Text = "Panic Button";
                      txtbxEngineFast.Text = "ON";
                  }
                  else if (engine == "5")
                  {
                      txtbxAlertActive.Text = "Panic Button";
                      txtbxEngineFast.Text = "OFF";
                  }
                  else if (engine == "8" || engine == "C")
                  {
                      txtbxAlertActive.Text = "Seatbelt ON";
                  }
                  else if (engine == "9" || engine == "D")
                  {
                      txtbxAlertActive.Text = "Panic Button and Seatbelt ON";
                  }
                  else if (engine == "A" || engine == "E")
                  {
                      txtbxAlertActive.Text = "Seatbelt ON";
                      txtbxEngineFast.Text = "ON";
                  }
                  else if (engine == "B" || engine == "F")
                  {
                      txtbxAlertActive.Text = "Seatbelt ON and Panic Button";
                      txtbxEngineFast.Text = "ON";
                  }
              }
              string status = input.Substring(24, 1);
              if (status == "A")
              {
                  txtbxDevStatus.Text = "OK";
              }
              else
              {
                  txtbxDevStatus.Text = "Message Not Valid";
              }
              string determinator = input.Substring(16, 3);
              if (determinator == "RA1")
              {
                  txtbxDevType.Text = "R10-V2";
              }
              txtbxLastValidDateTime.Text = finnow.ToString();
          }
          else
          {
              MessageBox.Show("NOT 105"); 
          }
      }
  }
  </code></pre>