예제 #1
0
파일: BatteryTask.cs 프로젝트: Anpl-sc/Labs
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
파일: BatteryTask.cs 프로젝트: Anpl-sc/Labs
        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();
        }
예제 #4
0
        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();
        }