public override void StartCharge(int delay) { var chargeTask = new Action(async() => { CanCharge = true; while (CanCharge) { await Task.Run(async() => { await Task.Delay(delay); lock (SyncObject) { if (Charge < MaxCharge) { Charge++; } else { StopCharge(); } ShowCharge?.Invoke(this, Charge); } }); } }); chargeTask.Invoke(); }
public override void Discharge(int delay) { Thread dischargeThread = new Thread(() => { while (CanDischarge) { Thread.Sleep(delay); lock (SyncObject) { if (Charge > 0) { Charge--; } ShowCharge?.Invoke(this, Charge); } } }); dischargeThread.Start(); }
public override void Discharge(int delay) { var dischargeTask = new Action(async() => { while (CanDischarge) { await Task.Run(async() => { await Task.Delay(delay); lock (SyncObject) { if (Charge > 0) { Charge--; } ShowCharge?.Invoke(this, Charge); } }); } }); dischargeTask.Invoke(); }
public override void StartCharge(int delay) { Thread chargeThread = new Thread(() => { CanCharge = true; while (CanCharge) { Thread.Sleep(delay); lock (SyncObject) { if (Charge < MaxCharge) { Charge++; } else { StopCharge(); } ShowCharge?.Invoke(this, Charge); } } }); chargeThread.Start(); }