internal static async Task <(bool started, string failReason)> StartDeviceTask(ComputeDevice device) { device.StartState = true; // we can only start a device it is already stopped if (device.State == DeviceState.Disabled) { return(false, "Device is disabled"); } if (device.State != DeviceState.Stopped && device.State != DeviceState.Error) { return(false, "Device already started"); } var started = true; var failReason = ""; var allAlgorithmsDisabled = !device.AnyAlgorithmEnabled(); var isAllZeroPayingState = device.AllEnabledAlgorithmsZeroPaying(); // check if device has any benchmakrs var needBenchmarkOrRebench = device.AnyEnabledAlgorithmsNeedBenchmarking(); if (allAlgorithmsDisabled) { device.State = DeviceState.Error; started = false; failReason = "Cannot start a device with all disabled algoirhtms"; } else if (isAllZeroPayingState && !needBenchmarkOrRebench) { device.State = DeviceState.Error; started = false; failReason = "No enabled algorithm is profitable"; } else { await MiningManager.StartDevice(device); } return(started, failReason); }