using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace charger_gui.operations { class DischargeOperation : AutomaticOperation { const float MIN_VOLTAGE = 10.8f; private int passed; private bool isComplete = false; public override string Status { get { if (isComplete) return "Discharging complete in " + passed + " seconds"; else return "Discharging, passed " + passed + " seconds"; } } public DischargeOperation(Logger log, MainWindowViewModel model) : base(log, model) { } protected override void Work() { log.Log("Discharging started"); var start = DateTime.Now; model.IsCharging = false; model.IsLampOn = true; Thread.Sleep(500); while (model.U2Acc > MIN_VOLTAGE) { Thread.Sleep(1000); passed = (int)((DateTime.Now - start).TotalSeconds); OnStatusChanged(); log.Log("Discharging " + passed + "s " + model.U2Acc.ToString("F4")); } log.Log("Discharging complete in " + passed + " seconds"); isComplete = true; OnStatusChanged(); } } }