Ejemplo n.º 1
0
        public void StopAllMiners()
        {
            if (_runningGroupMiners != null)
            {
                foreach (var groupMiner in _runningGroupMiners.Values)
                {
                    groupMiner.End();
                }

                _runningGroupMiners = new Dictionary <string, GroupMiner>();
            }

            if (_ethminerNvidiaPaused != null)
            {
                _ethminerNvidiaPaused.End();
                _ethminerNvidiaPaused = null;
            }

            if (_ethminerAmdPaused != null)
            {
                _ethminerAmdPaused.End();
                _ethminerAmdPaused = null;
            }

            _switchingManager.Stop();

            _mainFormRatesComunication?.ClearRatesAll();

            // restroe/enable sleep
            _preventSleepTimer.Stop();
            _internetCheckTimer.Stop();
            Helpers.AllowMonitorPowerdownAndSleep();
        }
Ejemplo n.º 2
0
        public static async Task StopAllMiners()
        {
            EthlargementIntegratedPlugin.Instance.Stop();
            await _semaphore.WaitAsync();

            try
            {
                foreach (var groupMiner in _runningMiners.Values)
                {
                    groupMiner.End();
                }
                _runningMiners.Clear();

                //// TODO enable StabilityAnalyzer
                //// Speed stability analyzer was here or deviant algo checker
                //foreach (var miningDev in _miningDevices)
                //{
                //    var deviceUuid = miningDev.Device.Uuid;
                //    foreach (var algorithm in miningDev.Algorithms)
                //    {
                //        var speedID = $"{deviceUuid}-{algorithm.AlgorithmStringID}";
                //        var isDeviant = BenchmarkingAnalyzer.IsDeviant(speedID);
                //        if (isDeviant)
                //        {
                //            var stableSpeeds = BenchmarkingAnalyzer.GetStableSpeeds(speedID);
                //            if (stableSpeeds != null)
                //            {
                //                algorithm.Speeds = stableSpeeds;
                //            }
                //        }
                //    }
                //}
            }
            finally
            {
                _semaphore.Release();
            }

            _switchingManager?.Stop();
            ApplicationStateManager.ClearRatesAll();
            //_internetCheckTimer?.Stop();
        }
        private static async Task MiningManagerCommandQueueLoop(CancellationToken stop)
        {
            var switchingManager = new AlgorithmSwitchingManager();

            try
            {
                switchingManager.SmaCheck += SwichMostProfitableGroupUpMethod;
                switchingManager.ForceUpdate();

                var         checkWaitTime = TimeSpan.FromMilliseconds(50);
                Func <bool> isActive      = () => !stop.IsCancellationRequested;
                Logger.Info(Tag, "Starting MiningManagerCommandQueueLoop");
                while (isActive())
                {
                    if (isActive())
                    {
                        await TaskHelpers.TryDelay(checkWaitTime, stop);
                    }
                    // command handling
                    if (isActive() && _commandQueue.TryDequeue(out var command))
                    {
                        await HandleCommand(command);
                    }
                }
            }
            catch (TaskCanceledException e)
            {
                Logger.Debug(Tag, $"MiningManagerCommandQueueLoop TaskCanceledException: {e.Message}");
            }
            finally
            {
                Logger.Info(Tag, "Exiting MiningManagerCommandQueueLoop run cleanup");
                // cleanup
                switchingManager.SmaCheck -= SwichMostProfitableGroupUpMethod;
                switchingManager.Stop();
                foreach (var groupMiner in _runningMiners.Values)
                {
                    await groupMiner.StopTask();
                }
                _runningMiners.Clear();
                _miningDevices.Clear();
                EthlargementIntegratedPlugin.Instance.Stop();
            }
        }
Ejemplo n.º 4
0
        private static async Task MiningManagerCommandQueueLoop(CancellationToken stop)
        {
            var switchingManager = new AlgorithmSwitchingManager();

            var         lastDeferredCommandTime = DateTime.UtcNow;
            Func <bool> handleDeferredCommands  = () => (DateTime.UtcNow - lastDeferredCommandTime).TotalSeconds >= 0.5;
            var         deferredCommands        = new List <DeferredDeviceCommand>();

            try
            {
                switchingManager.SmaCheck += SwichMostProfitableGroupUpMethod;
                switchingManager.ForceUpdate();

                var         checkWaitTime = TimeSpan.FromMilliseconds(50);
                Func <bool> isActive      = () => !stop.IsCancellationRequested;
                Logger.Info(Tag, "Starting MiningManagerCommandQueueLoop");
                while (isActive())
                {
                    if (isActive())
                    {
                        await TaskHelpers.TryDelay(checkWaitTime, stop);
                    }
                    if (handleDeferredCommands() && deferredCommands.Any())
                    {
                        await HandleDeferredCommands(deferredCommands);

                        deferredCommands.Clear();
                    }
                    // command handling
                    var(command, hasTimedout, exceptionString) = await _commandQueue.ReadAsync(checkWaitTime, stop);

                    if (command == null)
                    {
                        if (exceptionString != null)
                        {
                            Logger.Error(Tag, $"Channel.ReadAsync error: {exceptionString}");
                        }
                        continue;
                    }
                    if (command is DeferredDeviceCommand deferredCommand)
                    {
                        deferredCommand.device.IsPendingChange = true; // TODO check if we can be without this one
                        deferredCommand.device.State           = DeviceState.Pending;
                        lastDeferredCommandTime = DateTime.UtcNow;
                        deferredCommands.Add(deferredCommand);
                        continue;
                    }
                    if (command is MainCommand mainCommand)
                    {
                        await HandleCommand(mainCommand);
                    }
                }
            }
            catch (TaskCanceledException e)
            {
                Logger.Debug(Tag, $"MiningManagerCommandQueueLoop TaskCanceledException: {e.Message}");
            }
            finally
            {
                Logger.Info(Tag, "Exiting MiningManagerCommandQueueLoop run cleanup");
                // cleanup
                switchingManager.SmaCheck -= SwichMostProfitableGroupUpMethod;
                switchingManager.Stop();
                foreach (var groupMiner in _runningMiners.Values)
                {
                    await groupMiner.StopTask();
                }
                _runningMiners.Clear();
                _miningDevices.Clear();
            }
        }