// ================================== One Second Timer: private void timer1_Tick_1(object sender, EventArgs e) { // label_TempF.Text = DateTime.Now.ToString(); // Get Weather // ========== 15 min loop try { if (false) //timesecs % 3000 == 0) { string details = ""; weather w = new weather(); int temperature = w.CheckWeather("Pearl,Mississippi", out details); // int tempF = (int)((1.8f * temperature + 32.0f) + 0.5); // F // richTextBox1.Text = " CONTROL SYSTEMS Production Tracking [Temperature Jackon,MS " + temperature.ToString("0")+"]"; label_currentTIme.Text = string.Format("{0}\u00B0F", temperature) + " " + details; } } catch (Exception excp) { // MessageBox.Show(excp.ToString()); // Remove } if (timesecs % 30 == 0) { this.Invoke((MethodInvoker) delegate { GetDataAndCopyToDataGrid(); }); } //if (timesecs % 30 == 0) //{ // // Get Data // List<ProductionJobInfo> sqlresults = Database.GetProductionInfoData(); // DisplayResultsOnDataGrid(sqlresults); // //// GetDataAndCopyToDataGrid(); // //if (workerThreadRunning == false) // //{ // // // Initialise and start worker thread // // this.workerThread = new Thread(new ThreadStart(this.GetDataAndCopyToDataGrid)); // // this.workerThread.Start(); // //} //} timesecs++; //label_TempF.Text = DateTime.Now.ToString(); //// Get Weather //// ========== 15 min loop //try //{ // if (timesecs % 3000 == 0) // { // string details = ""; // weather w = new weather(); // int temperature = w.CheckWeather("Pearl,Mississippi", out details); // // int tempF = (int)((1.8f * temperature + 32.0f) + 0.5); // F // // richTextBox1.Text = " CONTROL SYSTEMS Production Tracking [Temperature Jackon,MS " + temperature.ToString("0")+"]"; // label_currentTIme.Text = string.Format("{0}\u00B0F", temperature) + " " + details; // } //} //catch (Exception excp) //{ // MessageBox.Show(excp.ToString()); // Remove //} ////if (timemins % 30 == 0) ////{ //// // GetDataAndCopyToDataGrid(); //// if (workerThreadRunning == false) //// { //// // Initialise and start worker thread //// this.workerThread = new Thread(new ThreadStart(this.GetDataAndCopyToDataGrid)); //// this.workerThread.Start(); //// } ////} //timesecs++; }
void timer_Elapsed(object state) { // Thread.Sleep(1000); try { if (timesecsElapsed % 300 == 0) // Get weather every 5 mins: { string details = ""; weather w = new weather(); int temperature = w.CheckWeather("Pearl,Mississippi", out details); // int tempF = (int)((1.8f * temperature + 32.0f) + 0.5); // F // richTextBox1.Text = " CONTROL SYSTEMS Production Tracking [Temperature Jackon,MS " + temperature.ToString("0")+"]"; strWeather = string.Format("{0}\u00B0F", temperature) + " " + details; } } catch (Exception excp) { // MessageBox.Show(excp.ToString()); // Remove } this.Invoke((MethodInvoker) delegate { label_TempF.Text = DateTime.Now.ToString(); label_currentTIme.Text = strWeather; }); // =============================== Update: SQL Query every 15 mins if (timesecsElapsed % 900 == 0) { GetDataAndCopyToDataGrid(); } // Scroll top and bottom (in case we have over 30 rows) if (timesecsElapsed % 15 == 0) { this.Invoke((MethodInvoker) delegate { // if (dataGridView1.DataSource != null) // { if (dataGridView1.Rows.Count > 28) // Use scroll control: { if (togglescroll == true) { dataGridView1.FirstDisplayedScrollingRowIndex = 1; togglescroll = false; } else { dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1; togglescroll = true; } } // } }); } timesecsElapsed++; updateTimer.Change(1000, Timeout.Infinite); }