private void WaitForService_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { BackgroundWorker1.CancelAsync(); } }
private void UcHome_BtnStart_Click(object sender, EventArgs e) { if (isStart == false) { isStart = true; ucHome1.PicBoxStatus.Image = Properties.Resources.active; ucHome1.LblStatus.Text = "Active"; ucHome1.TbError.Text = ""; ucHome1.TbError.Visible = false; ucHome1.BtnStart.Text = "STOP"; ucSettings1.TrkBarRefreshDelay.Enabled = false; ucSettings1.TrkBarReconnectDelay.Enabled = false; ucSettings1.NumUDExchangeRate.Enabled = false; ucSettings1.BtnReset.Enabled = false; ucSettings1.BtnSave.Enabled = false; CancelToken = new CancellationTokenSource(); BackgroundWorker1.RunWorkerAsync(); } else { ucHome1.BtnStart.Text = "PLEASE WAIT"; BackgroundWorker1.CancelAsync(); CancelToken.Cancel(); } }
void LoadLocalStream(string LocalFile) { if (LocalFile.Contains(".mp4") == true || LocalFile.Contains(".avi") == true || LocalFile.Contains(".mkv") == true || LocalFile.Contains(".flv") == true || LocalFile.Contains(".mpg") == true || LocalFile.Contains(".webm") == true || LocalFile.Contains(".divx") == true || LocalFile.Contains(".mov") == true || LocalFile.Contains(".m4v") == true || LocalFile.Contains(".wmv") == true) { if (WS1.IsSocketOpen() == false) { IsLocalStream = true; TempFilePath = LocalFile; ConnectChromecast(); Timer4.Start(); return; } WebSvr1.CleanTempFiles(); if (IsTranscoding == true) { if (BackgroundWorker1.IsBusy == true) { BackgroundWorker1.CancelAsync(); } if (gProcess.HasExited == false) { gProcess.Kill(); } } VideoTitle = LocalFile; VideoTitle = Regex.Split(LocalFile, @"\\")[Regex.Split(LocalFile, @"\\").Length - 1]; Label3.Text = VideoTitle; if (LocalFile.Contains(".mp4") == true) { IsTranscoding = false; AppLog("Streaming: " + LocalFile); WebSvr1.VideoFile(LocalFile); WS1.SendMessage(UTL1.LoadPlayURL(VideoTitle, "http://" + LocalIP + ":" + LocalPort + "/video.mp4")); } else { Thread.Sleep(1000); AppLog("Transcoding: " + LocalFile); TrancodeFilePath = LocalFile; if (IsTranscoding == true && BackgroundWorker1.IsBusy == true) { if (BackgroundWorker1.CancellationPending == true) { Timer3.Start(); } return; } IsTranscoding = true; BackgroundWorker1.WorkerSupportsCancellation = true; BackgroundWorker1.RunWorkerAsync(); } } }
void LoadNetWorkStream(string Networkfile) { if (Networkfile.Contains(".mp4") == true || Networkfile.Contains(".avi") == true || Networkfile.Contains(".mkv") == true || Networkfile.Contains(".flv") == true || Networkfile.Contains(".mpg") == true || Networkfile.Contains(".webm") == true || Networkfile.Contains(".divx") == true || Networkfile.Contains(".mov") == true || Networkfile.Contains(".m4v") == true || Networkfile.Contains(".wmv") == true) { if (WS1.IsSocketOpen() == false) { IsLocalStream = false; TempFilePath = Networkfile; ConnectChromecast(); Timer4.Start(); return; } WebSvr1.CleanTempFiles(); if (IsTranscoding == true) { if (BackgroundWorker1.IsBusy == true) { BackgroundWorker1.CancelAsync(); } if (gProcess.HasExited == false) { gProcess.Kill(); } } string VideoURL = Networkfile; string Videofile = Regex.Split(VideoURL, "/")[Regex.Split(VideoURL, "/").Length - 1]; Label3.Text = Videofile; if (Videofile.Substring(Videofile.Length - 4, 4).ToLower() == ".mp4") { IsTranscoding = false; VideoTitle = Videofile; WS1.SendMessage(UTL1.LoadPlayURL(VideoTitle, VideoURL)); } else { Thread.Sleep(1000); TrancodeFilePath = VideoURL; VideoTitle = Videofile; AppLog("Transcoding: " + VideoURL); if (IsTranscoding == true && BackgroundWorker1.IsBusy == true) { if (BackgroundWorker1.CancellationPending == true) { Timer3.Start(); } return; } IsTranscoding = true; BackgroundWorker1.WorkerSupportsCancellation = true; BackgroundWorker1.RunWorkerAsync(); } } }
private void btnStop_Click_1(object sender, EventArgs e) { BackgroundWorker1.CancelAsync(); this.Invoke(new MethodInvoker(() => pbarProgressBar1.Value = 0)); this.Invoke(new MethodInvoker(() => txtOutput.Text = txtOutput.Text.Replace(waitMessage, ""))); signalFails = 0; txtSignal.BackColor = Control.DefaultBackColor; txtSignal.Text = ""; txtBattery.BackColor = Control.DefaultBackColor; txtBattery.Text = ""; txtLastUpdated.Text = ""; txtSignalFails.Text = ""; this.Invoke(new MethodInvoker(() => txtOutput.Text = "Stopped." + System.Environment.NewLine + txtOutput.Text)); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\DeskCastC", "ROOTED", IsRooted.ToString()); DSC1.StopDiscovery(); WebSvr1.CleanTempFiles(); if (BackgroundWorker1.IsBusy == true) { BackgroundWorker1.CancelAsync(); } gProcess.Kill(); Environment.Exit(0); } catch { Environment.Exit(0); } }
void ButtonStartClick(object sender, System.EventArgs e) { // routine assumes backgroundWorker was started in // MainForm constructor //toggle Capture if (CaptureEnabled.Equals(true)) { // if capturing was enabled BackgroundWorker1.CancelAsync(); // this will result in event handler BackgroundWorker1_RunWorkerCompleted // and the button color and text will be changes. } else { // if capturing was disabled BackgroundWorker1.RunWorkerAsync(); CaptureEnabled = true; this.buttonStart.BackColor = System.Drawing.Color.LightGreen; this.buttonStart.Text = "Stop Capturing Clipboard Changes."; } }
public void cancel() { Cancel = true; BackgroundWorker1.CancelAsync(); viewUpdate(false); }
private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { int startAttempts = 0; string currentStatus; Invoke(new MethodInvoker(() => { this.Text = svcName; })); if (LoadSettings() == false) { BackgroundWorker1.CancelAsync(); } Thread.Sleep(10); do { if (BackgroundWorker1.CancellationPending == true) { return; } currentStatus = GetStatus(svcName); switch (currentStatus) { case "Running": Invoke(new MethodInvoker(() => { label1.Text = currentStatus; })); try { ProcessStartInfo startInfo = new ProcessStartInfo { FileName = appName, WindowStyle = (ProcessWindowStyle)appVis }; Process.Start(startInfo); } catch (Exception ex) { ModalMessageBox(ex.Message, ex.Source); Exit(1); break; } Exit(0); break; case "Stopped": Invoke(new MethodInvoker(() => { label1.Text = currentStatus; })); var svc = new ServiceController(svcName); try { svc.Start(); } catch (Exception ex) { ModalMessageBox(ex.Message, ex.Source); Exit(2); } break; case "StartPending": Invoke(new MethodInvoker(() => { label1.Text = currentStatus; })); Invoke(new MethodInvoker(() => { progressBar1.MarqueeAnimationSpeed = 10; })); Thread.Sleep(10); if (startAttempts++ > 10) { ModalMessageBox("Too many start attempts.", svcName); Exit(3); } break; default: ModalMessageBox(currentStatus, svcName); Exit(4); break; } do { Thread.Sleep(10); if (BackgroundWorker1.CancellationPending == true) { return; } } while (GetStatus(svcName).Equals(currentStatus)); Invoke(new MethodInvoker(() => { progressBar1.MarqueeAnimationSpeed = 0; })); } while (true); }
private void Exit(int status) { exitStatus = status; BackgroundWorker1.CancelAsync(); }
// Callback function invoked by Pcap.Net for every incoming packet private void PacketHandler(Packet packet) { if (!BackgroundWorker1.CancellationPending == true) { try { this.Invoke(new MethodInvoker(() => pbarProgressBar1.Visible = true)); if (packet.Ethernet.IpV4.Tcp.Payload != null) { Match match; string text = Encoding.ASCII.GetString(packet.Ethernet.IpV4.Tcp.Payload.ToMemoryStream().ToArray()); if (Properties.Settings.Default.filterOnSensorId.ToString().Length > 0) { match = Regex.Match(text.ToLower(), "sensor=" + Properties.Settings.Default.filterOnSensorId.ToString() + "|mt=pressure", RegexOptions.Singleline); } else if (Properties.Settings.Default.sensorType.ToString().Length > 0) { match = Regex.Match(text.ToLower(), "mt=" + Properties.Settings.Default.sensorType.ToString() + "|mt=pressure", RegexOptions.Singleline); } else { match = Regex.Match(text.ToLower(), "mt=", RegexOptions.Singleline); } string[] bridgeDataArray; double pressureOffset = Properties.Settings.Default.pressureOffset; if (match.Success) { this.Invoke(new MethodInvoker(() => pbarProgressBar1.Value = progressBarValue(10))); this.Invoke(new MethodInvoker(() => txtOutput.Text = txtOutput.Text.Replace(waitMessage, ""))); bridgeDataArray = text.Split('&'); if (text.IndexOf("mt=" + Properties.Settings.Default.sensorType.ToString(), StringComparison.CurrentCultureIgnoreCase) == -1) { noSensorDataIterations += 1; } else { noSensorDataIterations = 0; } foreach (string element in bridgeDataArray) { if (element.IndexOf("sensor=") == 0) { sensorId = element.Substring(7, 5); } if (element.IndexOf("mt=") == 0) { sensorType = element.Substring(3).ToLower(); } if (Properties.Settings.Default.filterOnSensorId.ToString().Length == 0 || sensorId == Properties.Settings.Default.filterOnSensorId.ToString()) { if (element.IndexOf("winddir=") == 0 && (Properties.Settings.Default.sensorTypeWind == "" || sensorType.IndexOf(Properties.Settings.Default.sensorTypeWind) != -1) && (Properties.Settings.Default.sensorIdWind == "" || sensorId.IndexOf(Properties.Settings.Default.sensorIdWind) != -1)) { windDirHex = element.Substring(8, 1); switch (windDirHex) { case "5": windDegrees = 0; break; case "7": windDegrees = 22.5; break; case "3": windDegrees = 45; break; case "1": windDegrees = 67.5; break; case "9": windDegrees = 90; break; case "B": windDegrees = 112.5; break; case "F": windDegrees = 135; break; case "D": windDegrees = 157.5; break; case "C": windDegrees = 180; break; case "E": windDegrees = 202.5; break; case "A": windDegrees = 225; break; case "8": windDegrees = 247.5; break; case "0": windDegrees = 270; break; case "2": windDegrees = 292.5; break; case "6": windDegrees = 315; break; case "4": windDegrees = 337.5; break; } } if (element.IndexOf("windspeed=") == 0 && (Properties.Settings.Default.sensorTypeWind == "" || sensorType.IndexOf(Properties.Settings.Default.sensorTypeWind) != -1) && (Properties.Settings.Default.sensorIdWind == "" || sensorId.IndexOf(Properties.Settings.Default.sensorIdWind) != -1)) { windspeed = Math.Round(double.Parse(element.Substring(11, 5)) / 44.70400004, 1); dtWindData.Rows.Add(new object[] { DateTime.Now, windspeed }); windGust = calcWindGust(windspeed); } if (element.IndexOf("temperature=") == 0 && (Properties.Settings.Default.sensorTypeTemp == "" || sensorType.IndexOf(Properties.Settings.Default.sensorTypeTemp) != -1) && (Properties.Settings.Default.sensorIdTemp == "" || sensorId.IndexOf(Properties.Settings.Default.sensorIdTemp) != -1)) { if (element.Substring(13, 1) == "-") { temperature = Math.Round(double.Parse(element.Substring(14, 4)) * -1 / 100 * 9 / 5 + 32, 1); } else { temperature = Math.Round(double.Parse(element.Substring(14, 4)) / 100 * 9 / 5 + 32, 1); } } if (element.IndexOf("humidity=") == 0 && (Properties.Settings.Default.sensorTypeHumidity == "" || sensorType.IndexOf(Properties.Settings.Default.sensorTypeHumidity) != -1) && (Properties.Settings.Default.sensorIdHumidity == "" || sensorId.IndexOf(Properties.Settings.Default.sensorIdHumidity) != -1)) { humidity = double.Parse(element.Substring(11, 3)) / 10; } if (element.IndexOf("rainfall=") == 0 && (Properties.Settings.Default.sensorTypeRain == "" || sensorType.IndexOf(Properties.Settings.Default.sensorTypeRain) != -1) && (Properties.Settings.Default.sensorIdRain == "" || sensorId.IndexOf(Properties.Settings.Default.sensorIdRain) != -1)) { currRain = Math.Round(double.Parse(element.Substring(10, 6)) / 2540, 3); if (currRain > 0) { cumulRainDay += currRain; cumulRainNoReset += currRain; } dtRainData.Rows.Add(new object[] { DateTime.Now, currRain }); rainHour = rainLast60Minutes(currRain); } if (element.IndexOf("rssi=") == 0) { signal = int.Parse(element.Substring(5, 1)); } if (element.IndexOf("battery=") == 0) { battery = element.Substring(8); } } // Get and process pressure data if (element.IndexOf("C1=") == 0) { c1 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("C2=") == 0) { c2 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("C3=") == 0) { c3 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("C4=") == 0) { c4 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("C5=") == 0) { c5 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("C6=") == 0) { c6 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("C7=") == 0) { c7 = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("A=") == 0) { a = Int32.Parse(element.Substring(3), NumberStyles.HexNumber); } if (element.IndexOf("B=") == 0) { b = Int32.Parse(element.Substring(3), NumberStyles.HexNumber); } if (element.IndexOf("C=") == 0) { c = Int32.Parse(element.Substring(3), NumberStyles.HexNumber); } if (element.IndexOf("D=") == 0) { d = Int32.Parse(element.Substring(3), NumberStyles.HexNumber); } if (element.IndexOf("PR=") == 0) { pr = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); } if (element.IndexOf("TR=") == 0) { tr = Int32.Parse(element.Substring(3, 4), NumberStyles.HexNumber); d1 = pr; d2 = tr; if (d2 >= c5) { dut = d2 - c5 - ((d2 - c5) / Math.Pow(2, 7)) * ((d2 - c5) / Math.Pow(2, 7)) * a / Math.Pow(2, c); } else { dut = d2 - c5 - ((d2 - c5) / Math.Pow(2, 7)) * ((d2 - c5) / Math.Pow(2, 7)) * b / Math.Pow(2, c); } off = (c2 + (c4 - 1024) * dut / Math.Pow(2, 14)) * 4; sens = c1 + c3 * dut / Math.Pow(2, 10); x = sens * (d1 - 7168) / Math.Pow(2, 14) - off; p = x * 10 / Math.Pow(2, 5) + c7; t = 250 + dut * c6 / Math.Pow(2, 16) - dut / Math.Pow(2, d); pressure = Math.Round(p / 338.6 + pressureOffset, 2); } if (humidity > 0) { dewpoint = ((((temperature - 32) / 1.8) - (14.55 + 0.114 * ((temperature - 32) / 1.8)) * (1 - (0.01 * humidity)) - Math.Pow(((2.5 + 0.007 * ((temperature - 32) / 1.8)) * (1 - (0.01 * humidity))), 3) - (15.9 + 0.117 * ((temperature - 32) / 1.8)) * Math.Pow((1 - (0.01 * humidity)), 14)) * 1.8) + 32; dewpoint = Math.Round(dewpoint, 1); } } if (txtOutput.Text.Length > 50000) { this.Invoke(new MethodInvoker(() => string.IsNullOrEmpty(txtOutput.Text))); } string wuResponse = null; string wBugResponse = null; string pwsResponse = null; string aWeatherResponse = null; if (pressure > 0 & (humidity > 0 || Properties.Settings.Default.filterOnSensorId.ToString() == "water" && temperature > 0) & noSensorDataIterations < 5) { if (Properties.Settings.Default.postToWunderground == true) { string wundergroundUpdateString = "http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?ID=" + Properties.Settings.Default.wuStation + "&PASSWORD="******"&dateutc=" + System.Uri.EscapeUriString(Convert.ToString(DateTime.Now.ToUniversalTime())) + "&winddir=" + windDegrees + "&windspeedmph=" + windspeed + "&tempf=" + temperature + "&rainin=" + rainHour + "&dailyrainin=" + cumulRainDay + "&baromin=" + pressure + "&dewptf=" + dewpoint + "&humidity=" + humidity + "&softwaretype=" + "Kevins%20Acu-Rapid%201217&action=updateraw&realtime=1&rtfreq=15" + "&windgustmph=" + windGust /*+ "&indoortempf=" + temperature + * "&soiltempf=" + temperature*/; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(wundergroundUpdateString); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); wuResponse = readStream.ReadToEnd(); readStream.Close(); response.Close(); if (wuResponse.IndexOf("success") != -1) { wuResponse = "ok"; } } catch (Exception ex) { wuResponse = ""; this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + "ERROR posting data to Weather Underground. " + ex.Message + System.Environment.NewLine + txtOutput.Text)); } } else { wuResponse = "off"; } if (Properties.Settings.Default.postToWeatherBug == true) { string weatherBugUpdateString = "http://data.backyard2.weatherbug.com/data/livedata.aspx?ID=" + Properties.Settings.Default.wbPub + "&Key=" + Properties.Settings.Default.wbPwd + "&num=" + Properties.Settings.Default.wbStation + "&dateutc=" + System.Uri.EscapeUriString(Convert.ToString(DateTime.Now.ToUniversalTime())) + "&winddir=" + windDegrees + "&windspeedmph=" + windspeed + "&windgustmph=" + windGust + "&tempf=" + temperature + "&rainin=" + rainHour + "&dailyrainin=" + cumulRainDay + "&baromin=" + pressure + "&dewptf=" + dewpoint + "&humidity=" + humidity + "&softwaretype=Kevin%27s%20Acu-Link"; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(weatherBugUpdateString); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); wBugResponse = readStream.ReadToEnd(); readStream.Close(); response.Close(); if (wBugResponse == "Successfully Received QueryString Data") { wBugResponse = "ok"; } } catch (Exception ex) { wBugResponse = ""; this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + "ERROR posting data to Weatherbug. " + ex.Message + System.Environment.NewLine + txtOutput.Text)); } } else { wBugResponse = "off"; } if (Properties.Settings.Default.postToPws == true) { string pwsUpdateString = "http://www.pwsweather.com/pwsupdate/pwsupdate.php?ID=" + Properties.Settings.Default.pwsStation + "&PASSWORD="******"&dateutc=" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd+HH\\%3Amm\\%3Ass") + "&winddir=" + windDegrees + "&windspeedmph=" + windspeed + "&windgustmph=" + windGust + "&tempf=" + temperature + "&rainin=" + rainHour + "&dailyrainin=" + cumulRainDay + "&baromin=" + pressure + "&dewptf=" + dewpoint + "&humidity=" + humidity + "&action=updateraw"; //this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + pwsUpdateString + // System.Environment.NewLine + txtOutput.Text)); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pwsUpdateString); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); pwsResponse = readStream.ReadToEnd(); readStream.Close(); response.Close(); if (pwsResponse.IndexOf("Data Logged and posted in METAR mirror") >= 0) { pwsResponse = "ok"; } } catch (Exception ex) { pwsResponse = ""; this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + "ERROR posting data to PWSweather. " + ex.Message + System.Environment.NewLine + txtOutput.Text)); } } else { pwsResponse = "off"; } if (Properties.Settings.Default.postToAWeather == true) { if (skipUpdateCount == 0 || skipUpdateCount >= skipUpdateInterval) { skipUpdateCount = 0; string aWeatherUpdateString = "http://www.anythingweather.com/feeds/load/WXDATAPOST.ASP?username="******"&password="******"&version=1&WXData=" + DateTime.Now.ToString("yyyy\\%2DMM\\%2Ddd+HH:mm:ss") + "%2C" + temperature + "%2C" + dewpoint + "%2C" + humidity + "%2C" + pressure + "%2C" + windDegrees + "%2C" + windspeed + "%2C" + cumulRainDay + "%2C%2C%2C" + windGust + "%2C%0D"; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(aWeatherUpdateString); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); aWeatherResponse = readStream.ReadToEnd(); readStream.Close(); response.Close(); if (aWeatherResponse == "") { aWeatherResponse = "ok"; //aWeatherResponse = aWeatherUpdateString; } } catch (Exception ex) { aWeatherResponse = ""; this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + "ERROR posting data to Anything Weather. " + ex.Message + System.Environment.NewLine + txtOutput.Text)); } } else { aWeatherResponse = "wait " + skipUpdateCount.ToString(); } } else { aWeatherResponse = "off"; } skipUpdateCount += 1; if (Properties.Settings.Default.writeToCSV == true) { string newFileName; if (Properties.Settings.Default.csvFilePath == "") { newFileName = "weather.csv"; } else { newFileName = Properties.Settings.Default.csvFilePath; } string weatherData = DateTime.Now + "," + temperature + "," + humidity + "," + windspeed + "," + windGust + "," + windDegrees + "," + pressure + "," + rainHour + "," + cumulRainDay + "," + dewpoint + Environment.NewLine; if (!File.Exists(newFileName)) { string fileHeader = "Local Time" + "," + "Temperature" + "," + "Humidity" + "," + "Wind MPH" + "," + "Wind Gust" + "," + "Wind Dir" + "," + "Pressure" + "," + "Rain Hour" + "," + "Rain Day" + "," + "Dewpoint" + Environment.NewLine; File.WriteAllText(newFileName, fileHeader); } File.AppendAllText(newFileName, weatherData); } } else { wuResponse = "Need more data"; wBugResponse = "Need more data"; pwsResponse = "Need more data"; aWeatherResponse = "Need more data"; } this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + " " + "T:" + temperature.ToString("F1") + " " + "H:" + humidity + " " + "W:" + windDegrees + "\t" + "WS:" + windspeed.ToString("F1") + "\t" + "Gust:" + windGust.ToString("F1") + "\t" + "RDAY:" + cumulRainDay.ToString("F2") + " " + "RHR:" + rainHour.ToString("F2") + " " + "BAR:" + pressure.ToString("F2") + " " + "DEW:" + dewpoint.ToString("F1") + " " + "SI: " + sensorId + " ST: " + sensorType + " " + "WU: " + wuResponse + " " + "WB: " + wBugResponse + " " + "PWS: " + pwsResponse + " " + "AW: " + aWeatherResponse + System.Environment.NewLine + txtOutput.Text)); this.Invoke(new MethodInvoker(() => txtBattery.Text = battery)); if (battery == "normal") { this.Invoke(new MethodInvoker(() => txtBattery.BackColor = Control.DefaultBackColor)); } else { this.Invoke(new MethodInvoker(() => txtBattery.BackColor = Color.FromArgb(247, 247, 124))); } this.Invoke(new MethodInvoker(() => txtSignal.Text = signal.ToString())); switch (signal) { case 0: this.Invoke(new MethodInvoker(() => txtSignal.BackColor = Color.Red)); break; case 1: this.Invoke(new MethodInvoker(() => txtSignal.BackColor = Color.FromArgb(247, 247, 124))); break; case 2: case 3: case 4: this.Invoke(new MethodInvoker(() => txtSignal.BackColor = Control.DefaultBackColor)); break; } this.Invoke(new MethodInvoker(() => txtLastUpdated.Text = DateTime.Now.ToString())); if (DateTime.Now.Day != previousDay) { cumulRainDay = 0; } previousDay = DateTime.Now.Day; previousRainReading = currRain; if (noSensorDataIterations >= 5) { this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + "INFO: Not receiving data from sensor. Low batteries? Too far away?" + System.Environment.NewLine + txtOutput.Text)); battery = "unknown"; signal = 0; signalFails += 1; } this.Invoke(new MethodInvoker(() => txtSignalFails.Text = signalFails.ToString())); } } } catch (NullReferenceException ex) { //Keep going } catch (Exception ex) { this.Invoke(new MethodInvoker(() => txtOutput.Text = "ERROR: " + ex.Message + " " + ex.Source + System.Environment.NewLine + txtOutput.Text)); } } else { communicator.Break(); BackgroundWorker1.CancelAsync(); BackgroundWorker1.Dispose(); } }
private void btncancel_Click(object sender, EventArgs e) { BackgroundWorker1.CancelAsync(); btncancel.Enabled = false; }