Esempio n. 1
0
        public static void StopMiner(bool manually = false)
        {
            if (!process?.HasExited == true)
            {
                ManuallyStoped = true;
            }

            if (manually)
            {
                inactivity = false;
                InactivityTimer?.Invoke(-1);
            }
            else
            {
                WachdogInactivity();
            }

            Waching = false;
            WachdogDelayTimer?.Invoke(-1);
            LowHashrate = false;
            LowHashrateTimer?.Invoke(-1);

            //Kill miner
            var processes = Process.GetProcesses().
                            Where(p => ProcessNames.Contains(p.ProcessName));
            var res = Parallel.ForEach(processes, p =>
            {
                while (!p.HasExited)
                {
                    try { p.Kill(); } catch { }
                }
            });

            while (!res.IsCompleted)
            {
                Thread.Sleep(50);
            }
        }
Esempio n. 2
0
        private static void StartWaching(double minhash)
        {
            WachdogThread?.Abort();
            WachdogThread = new Thread(() =>
            {
                WachdogInactivity();
                Waching = true;
                double?[] hashes;
                IEnumerable <double?> activehashes;
                for (int i = Settings.Profile.TimeoutWachdog; i > -1; i--)
                {
                    if (!Waching)
                    {
                        return;
                    }
                    Task.Run(() =>
                    {
                        try
                        {
                            activehashes = GetMinerInfo().Hashrates.Where(h => h != null);
                            if (activehashes.Sum() > minhash)
                            {
                                inactivity = false;
                                InactivityTimer?.Invoke(-1);
                            }
                        }
                        catch { }
                    });
                    Task.Run(() => { WachdogDelayTimer?.Invoke(i); });
                    Thread.Sleep(1000);
                }
                Action WachdogLoop = (() =>
                {
                    hashes = GetMinerInfo().Hashrates;
                    if (hashes != null)
                    {
                        activehashes = hashes.Where(h => h != null);
                        //Zero
                        if (activehashes.Sum() == 0)
                        {
                            ErrorsCounter++;
                            if (ErrorsCounter > 4)
                            {
                                Task.Run(() => ZeroHash?.Invoke());
                                WachdogInactivity();
                                Waching = false;
                                return;
                            }
                        }
                        else
                        {
                            // низкий хешрейт
                            if (activehashes.Sum() < minhash)
                            {
                                WachdogLowHashrate();
                            }
                            else
                            {
                                // блок хорошего поведения
                                LowHashrate = false;
                                Inactivity = false;
                                ErrorsCounter = 0;
                            }

                            //отвал карт
                            if (hashes.Contains(0))
                            {
                                ErrorsCounter++;
                                if (ErrorsCounter > 4)
                                {
                                    List <int> gpus = new List <int>();
                                    for (int i = 0; i < hashes.Length; i++)
                                    {
                                        if (hashes[i] == 0)
                                        {
                                            gpus.Add(i);
                                        }
                                    }
                                    Task.Run(() => GPUsfalled?.Invoke(gpus.ToArray()));
                                    Waching = false;
                                    return;
                                }
                            }
                        }
                        return;
                    }
                    else
                    {
                        //бездаействие
                        ErrorsCounter++;
                        if (ErrorsCounter > 4)
                        {
                            Task.Run(() => ZeroHash?.Invoke());
                            WachdogInactivity();
                            Waching = false;
                            return;
                        }
                    }
                    WachdogInactivity();
                });
                while (Waching)
                {
                    var WachResult = WachdogLoop.BeginInvoke(null, null);
                    Thread.Sleep(1000);
                    WachdogLoop.EndInvoke(WachResult);
                }
            });
            WachdogThread.Start();
        }