private StartStopMineButtonViewModel() { if (Design.IsInDesignMode) { return; } #if DEBUG Write.Stopwatch.Restart(); #endif this.StartMine = new DelegateCommand(() => { this.MinerProfile.IsMining = true; NTMinerRoot.Instance.StartMine(); BtnStopText = "正在挖矿"; }); this.StopMine = new DelegateCommand(() => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerRoot.IsAutoStartCanceled = true; NTMinerRoot.Instance.StopMineAsync(() => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }); if (NTMinerRoot.IsAutoStart && !this.MinerProfile.IsMining) { this.MinerProfile.IsMining = true; int n = MinerProfile.AutoStartDelaySeconds; Bus.IDelegateHandler handler = null; handler = AppContext.On <Per1SecondEvent>("挖矿倒计时", LogEnum.None, action: message => { if (NTMinerRoot.IsAutoStartCanceled) { BtnStopText = $"尚未开始"; n = 0; } else { BtnStopText = $"倒计时({--n})"; } if (n <= 0) { VirtualRoot.UnPath(handler); if (!NTMinerRoot.IsAutoStartCanceled) { BtnStopText = "正在挖矿"; MinerProfile.IsMining = true; NTMinerRoot.Instance.StartMine(); } } }); } #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private StartStopMineButtonViewModel() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif this.StartMine = new DelegateCommand(() => { this.MinerProfile.IsMining = true; NTMinerRoot.Instance.StartMine(); BtnStopText = "正在挖矿"; }); this.StopMine = new DelegateCommand(() => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerRoot.IsAutoStartCanceled = true; NTMinerRoot.Instance.StopMineAsync(() => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }); if (NTMinerRoot.IsAutoStart && !this.MinerProfile.IsMining && VirtualRoot.SecondCount < 10) { this.MinerProfile.IsMining = true; int n = 10 - VirtualRoot.SecondCount; Bus.IDelegateHandler handler = null; handler = On <Per1SecondEvent>("挖矿倒计时", LogEnum.None, action: message => { BtnStopText = $"倒计时({--n})"; if (n <= 0) { BtnStopText = "正在挖矿"; VirtualRoot.UnPath(handler); } }); } #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }