private void backgroundWorkerReadScale_DoWork(object sender, DoWorkEventArgs e) { while (true) { if (testStopped) { Debug.WriteLine("RETURN; hit"); Debug.WriteLine("RETURN; hit"); Debug.WriteLine("RETURN; hit"); return; } if (openValve1) { COMMS.openValve4(); openValve1 = false; } if (closeValve1) { COMMS.closeValve4(); closeValve1 = false; } scaleReading = COMMS.ReadScaleAWS(); if (scaleReading.Length > 4) { //lastValidScaleReading = filterReading(scaleReading); lastValidScaleReading = CommonClass.filterRegex(scaleReading); backgroundWorkerReadScale.ReportProgress(0); } if (testStopped) { Debug.WriteLine("testStopped hit"); Debug.WriteLine("testStopped hit"); Debug.WriteLine("testStopped hit"); return; } if ((backgroundWorkerReadScale.CancellationPending == true)) { Debug.WriteLine("e.Cancel ; hit"); Debug.WriteLine("e.Cancel ; hit"); Debug.WriteLine("e.Cancel ; hit"); e.Cancel = true; //break; return; } Thread.Sleep(150); } }
private void backgroundWorkerReadScale_DoWork(object sender, DoWorkEventArgs e) { while (true) { if (testStopped) { Debug.WriteLine("RETURN; hit"); Debug.WriteLine("RETURN; hit"); Debug.WriteLine("RETURN; hit"); return; } if (openValve1) { COMMS.openValve4(); openValve1 = false; } if (closeValve1) { COMMS.closeValve4(); closeValve1 = false; } if (openValve2) { COMMS.openValve2(); openValve2 = false; } if (openValve3) { COMMS.openValve3(); openValve3 = false; } if (closeValve2) { COMMS.closeValve2(); //MessageBox.Show("Test"); closeValve2 = false; } if (closeValve3) { COMMS.closeValve3(); closeValve3 = false; } scaleReading = COMMS.ReadScaleAWS(); if (scaleReading.Length > 4) { //lastValidScaleReading = filterReading(scaleReading); lastValidScaleReading = CommonClass.filterRegex(scaleReading); backgroundWorkerReadScale.ReportProgress(0); } /* * scaleReading = COMMS.ReadScaleAWS(); * //if (scaleReading != "" && !scaleReading.Contains("M") && scaleReading.Length > 2) * if (scaleReading != "" && scaleReading.Length > 4) * { * splitReceived = scaleReading.Split(new string[] { "g" }, StringSplitOptions.None); * splitReceived = splitReceived[0].Split(new string[] { ":" }, StringSplitOptions.None); * scaleReading = splitReceived[1]; * //scaleReading = scaleReading.Substring(2, scaleReading.Length - 3); * if (scaleReading != "") * { * lastValidScaleReading = scaleReading; * } * * * backgroundWorkerReadScale.ReportProgress(0); * if ((backgroundWorkerReadScale.CancellationPending == true)) * { * Debug.WriteLine("e.Cancel ; hit"); * Debug.WriteLine("e.Cancel ; hit"); * Debug.WriteLine("e.Cancel ; hit"); * e.Cancel = true; * break; * } * } */ Thread.Sleep(150); } }