public BatteryChargerThread(BatteryBase battery) { Battery = battery; ChargeBatteryThread = new Thread(() => ChargeBattery(battery)); ChargeBatteryThread.Start(); BatteryDischarger = new BatteryDischargerThread(battery); }
public void ChargeBattery(BatteryBase battery) { while (true) { chargeEvent.WaitOne(); lock (battery) { try { battery.Charge += 100; } catch (ArgumentException) { battery.Charge += battery.Capacity - battery.Charge; chargeEvent.Reset(); } Thread.Sleep(2000); } } }
public BatteryDischargerThread(BatteryBase battery) { Battery = battery; BatteryThread = new Thread(BatteryDischarging); BatteryThread.Start(); }
public BatteryDischargerTask(BatteryBase battery) { Battery = battery; BatteryTask = new Task(BatteryDischarging); BatteryTask.Start(); }