public void CancelTimer() { StateObjClass State = (StateObjClass)StateObj; State.TimerReference.Dispose(); log.Info("Disposed of timer."); }
public static void RunTimer() { StateObjClass StateObj = new StateObjClass(); StateObj.TimerCanceled = false; StateObj.SomeValue = 1; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(TimerTask); // Create a timer that calls a procedure every 2 seconds. // Note: There is no Start method; the timer starts running as soon as // the instance is created. System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, StateObj, 2000, 2000); // Save a reference for Dispose. StateObj.TimerReference = TimerItem; // Run for ten loops. while (StateObj.SomeValue < 10) { // Wait one second. System.Threading.Thread.Sleep(1000); } // Request Dispose of the timer object. StateObj.TimerCanceled = true; }
private void sendSensorUpdateProfile(System.Object state) { StateObjClass stateObjClass = (StateObjClass)state; if (tcpContext != null) { // Update Robot Sensor Profile robotBean.sensorProfile = new System.Collections.Generic.List <SensorBean>(); robotBean.actionProfile = incomingTcpMessage; float mDistance = distanceSensorController.distance; SensorBean distanceSensor = new SensorBean(1, "distance", "Laser"); distanceSensor.readout.Add(new SensorReadoutBean("m", "distance", mDistance.ToString())); float mDistanceFront = distanceSensorFrontController.distance; SensorBean distanceSensorFront = new SensorBean(2, "distance", "Laser"); distanceSensorFront.readout.Add(new SensorReadoutBean("m", "distance", mDistanceFront.ToString())); robotBean.sensorProfile.Add(distanceSensor); robotBean.sensorProfile.Add(distanceSensorFront); String strRobot = Regex.Replace(robotBean.toJSON().Trim(), @"\s+", ""); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strRobot + "\n"); output.Write(buffer, 0, buffer.Length); } else { stateObjClass.TimerReference.Dispose(); } }
public frmWaitingTime() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); _timer = new StateObjClass(this); UpdateCountDown(180); this.ResizeChildrenText(); //turn light and water GR.Instance.OutputCtrl.SetIngredientOn(8); }
public void RunTimer() { if (timeronrun == false) { timeronrun = true; StateObjClass StateObj = new StateObjClass(); StateObj.TimerCanceled = false; StateObj.SomeValue = 1; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(TimerTask); System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, StateObj, 1000, 1000); StateObj.TimerReference = TimerItem; } }
private static void StartUpdater() { var interval = 60000; StateObjClass stateObj = new StateObjClass(); stateObj.timerCanceled = false; stateObj.lastCheck = DateTime.Now; TimerCallback timerDelegate = new TimerCallback(Update); updater = new Timer(timerDelegate, stateObj, 0, interval); stateObj.timerReference = updater; }
private void TimerTask(object StateObj) { StateObjClass State = (StateObjClass)StateObj; // Use the interlocked class to increment the counter variable. System.Threading.Interlocked.Increment(ref State.SomeValue); Console.WriteLine("Launched new thread " + DateTime.Now.ToString()); if (State.TimerCanceled) // Dispose Requested. { State.TimerReference.Dispose(); Console.WriteLine("Done " + DateTime.Now.ToString()); } }
private void TimerTask(object StateObj) { StateObjClass State = (StateObjClass)StateObj; System.Threading.Interlocked.Increment(ref State.SomeValue); string data = DateTime.Now.ToLongTimeString(); Evaluate(); if (timeronrun == false) // Dispose Requested. { State.TimerReference.Dispose(); } }
public void RunTimer() { claimLinesList = new Dictionary <string, ClaimLinesIndex>(); StateObj = new StateObjClass(); StateObj.TimerCanceled = false; StateObj.TimerBusy = 0; StateObj.SomeValue = 1; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(TimerTask); // Create a timer that calls a procedure every 2 seconds. // Note: There is no Start method; the timer starts running as soon as // the instance is created. System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, StateObj, 10000, 10800000); // Changed timer to every 3 hours // Save a reference for Dispose. StateObj.TimerReference = TimerItem; }
public static void RunTimer(int timeOutInSec) { StateObjClass StateObj = new StateObjClass(); StateObj.MaxValue = (int) timeOutInSec / 1; StateObj.TimerCanceled = false; StateObj.SomeValue = 1; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(TimerTask); // Create a timer that calls a procedure every 2 seconds. // Note: There is no Start method; the timer starts running as soon as // the instance is created. System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, StateObj, 1000, 1000); // Save a reference for Dispose. StateObj.TimerReference = TimerItem; }
void Selected_Serial(object sender, EventArgs e, string selected_port) { Console.WriteLine("Selected port"); Console.WriteLine(selected_port); Console.ReadLine(); SelectedSerialPort = new SerialPort(selected_port); if (!SelectedSerialPort.IsOpen) { SelectedSerialPort.Open(); } ; StateObjClass StateObj = new StateObjClass(); StateObj.TimerCanceled = false; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(dataCheck); System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, StateObj, 1000, 3000); StateObj.TimerReference = TimerItem; // SelectedSerialPort.WriteLine("Send Data \n"); }
private void TimerTask(object StateObj) { try { StateObjClass State = (StateObjClass)StateObj; // Use the interlocked class to increment the counter variable. System.Threading.Interlocked.Increment(ref State.SomeValue); log.LogInformation("Launched new thread " + DateTime.Now.ToString()); //System.Diagnostics.Debug.WriteLine("Launched new thread " + DateTime.Now.ToString()); if (State.TimerCanceled) // Dispose Requested. { State.TimerReference.Dispose(); log.LogInformation("Done " + DateTime.Now.ToString()); //System.Diagnostics.Debug.WriteLine("Done " + DateTime.Now.ToString()); } else { log.LogInformation("Looking to Parse files"); if (State.TimerBusy == 0) { System.Threading.Interlocked.Add(ref State.TimerBusy, 1); log.LogInformation(String.Format("Before Parsing Files {0}", State.TimerBusy)); if (!IsProcessRunning()) { log.LogInformation(String.Format("Locking {0}", State.TimerBusy)); //if (LockProcess()) ParseFiles(); // Only SoftwareSandy is running now log.LogInformation(String.Format("Releasing the lock {0}", State.TimerBusy)); //ReleaseLock(); } System.Threading.Interlocked.Add(ref State.TimerBusy, -1); log.LogInformation(String.Format("After Parsing Files {0}", State.TimerBusy)); } } claimLinesList.Clear(); } catch (Exception ex) { log.LogError(String.Format("In Timer Task {0}", ex.Message)); } }
/* TCP CONNECTION HANDLERS*/ private void startTcpListener(object s) { StateObjClass StateObj = new StateObjClass(); StateObj.TimerCanceled = false; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(sendSensorUpdateProfile); System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, null, 0, 260); StateObj.TimerReference = TimerItem; while (true) { if (tcpListener.Pending()) { IAsyncResult result = tcpListener.BeginAcceptTcpClient(TcpListenerCallback, tcpListener); result.AsyncWaitHandle.WaitOne(250); } else { Thread.Sleep(100); } } }
void Selected_Serial(object sender, EventArgs e, string selected_port) { Console.WriteLine("Selected port"); Console.WriteLine(selected_port); Console.ReadLine(); SelectedSerialPort = new SerialPort(selected_port); if ( ! SelectedSerialPort.IsOpen) { SelectedSerialPort.Open(); }; StateObjClass StateObj = new StateObjClass(); StateObj.TimerCanceled = false; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(dataCheck); System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, StateObj, 1000, 3000); StateObj.TimerReference = TimerItem; // SelectedSerialPort.WriteLine("Send Data \n"); }
//protected override void SetVisibleCore(bool value) //{ // if (!_showWindow) // { // base.SetVisibleCore(false); // return; // } // base.SetVisibleCore(value); //} private void StartReadySignal() { textBox1.Text += string.Format("Starting to send EX_READY message...{0}", Environment.NewLine); _stateObj = new StateObjClass(); _stateObj.TimerCanceled = false; System.Threading.TimerCallback TimerDelegate = new System.Threading.TimerCallback(SendReadySignal); // Create a timer that calls a procedure every 2 seconds. // Note: There is no Start method; the timer starts running as soon as // the instance is created. System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, _stateObj, 100, 1000); // Save a reference for Dispose. _stateObj.TimerReference = TimerItem; textBox1.Text += string.Format("Waiting for EX_OK message...{0}", Environment.NewLine); }
private void dataCheck(object StateObj) { string cpuTemp = ""; string gpuTemp = ""; string gpuLoad = ""; string cpuLoad = ""; string ramUsed = ""; ; StateObjClass State = (StateObjClass)StateObj; // enumerating all the hardware foreach (OpenHardwareMonitor.Hardware.IHardware hw in thisComputer.Hardware) { Console.WriteLine("Checking: " + hw.HardwareType); Console.ReadLine(); hw.Update(); // searching for all sensors and adding data to listbox foreach (OpenHardwareMonitor.Hardware.ISensor s in hw.Sensors) { Console.WriteLine("Sensor: " + s.Name + " Type: " + s.SensorType + " Value: " + s.Value); Console.ReadLine(); if (s.SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature) { if (s.Value != null) { int curTemp = (int)s.Value; switch (s.Name) { case "CPU Package": cpuTemp = curTemp.ToString(); break; case "GPU Core": gpuTemp = curTemp.ToString(); break; } } } if (s.SensorType == OpenHardwareMonitor.Hardware.SensorType.Load) { if (s.Value != null) { int curLoad = (int)s.Value; switch (s.Name) { case "CPU Total": cpuLoad = curLoad.ToString(); break; case "GPU Core": gpuLoad = curLoad.ToString(); break; } } } if (s.SensorType == OpenHardwareMonitor.Hardware.SensorType.Data) { if (s.Value != null) { switch (s.Name) { case "Used Memory": decimal decimalRam = Math.Round((decimal)s.Value, 1); ramUsed = decimalRam.ToString(); break; } } } } } string curSong = ""; Process[] processlist = Process.GetProcesses(); foreach (Process process in processlist) { if (!String.IsNullOrEmpty(process.MainWindowTitle)) { if (process.ProcessName == "AIMP3") { curSong = process.MainWindowTitle; } else if (process.ProcessName == "foobar2000" && (process.MainWindowTitle.IndexOf("[") > 0)) { curSong = process.MainWindowTitle.Substring(0, process.MainWindowTitle.IndexOf("[") - 1); } } } string arduinoData = "C" + cpuTemp + "c " + cpuLoad + "%|G" + gpuTemp + "c " + gpuLoad + "%|R" + ramUsed + "G|S" + curSong + "|"; SelectedSerialPort.WriteLine(arduinoData); }
private static void OnTimedEvent(StateObjClass state) { state.CountDown(); }