Beispiel #1
0
 public void StopMining()
 {
     try
     {
         m_keepMining = false;
         Alarm.Clear();
         MiningCommand = MinerProgramCommand.Stop;
         //clear both queues so that threads wint start running them
         DownloadingQueue.Clear();
         //sometimes if downloaidnf thread is stuck in a long download and we want to stop we might hav to abort thread
         if (m_Downloading)
         {
             m_downloadingThread.Abort();
         }
         MiningQueue.Clear();
         RunningMiners.Clear();
         if (ActiveMiner != null)
         {
             ActiveMiner.StopMining();
             ActiveMiner = null;
         }
     }
     catch (Exception e)
     {
     }
 }
Beispiel #2
0
 void MiningThread(object obj)
 {
     IncrThreadCount();
     while (m_keepRunning)//thread runs as long as app is on
     {
         try
         {
             if (MiningQueue.Count == 0 || m_keepMining == false)
             {
                 Thread.Sleep(3000);
             }
             else
             {
                 IMinerProgram miner = MiningQueue.Dequeue();
                 if (miner.ReadyForMining())
                 {
                     try
                     {
                         miner.StartMining();
                         RunningMiners.Add(miner);
                     }
                     catch (Exception e)
                     {
                         Logger.Instance.LogError(e.Message);
                     }
                 }
                 else
                 {
                     DownloadingQueue.Enqueue(miner);
                 }
             }
             if (m_keepMining)
             {
                 try
                 {
                     List <IMinerProgram> stoppedMiners = new List <IMinerProgram>();
                     //Ensure all started miners are still running
                     for (int i = 0; i < RunningMiners.Count; i++)
                     {
                         IMinerProgram item = RunningMiners[i];
                         if (!item.Running())
                         {
                             item.SetRunningState(MinerProgramState.Stopped);
                             //just to be sure. we never want to start miner twice
                             item.KillMiner();
                             //Dont directly start mining. push it to queue and let the workflow start. also only if mining is stil on
                             if (m_keepMining)
                             {
                                 //MessageBox.Show(item.Miner.Name);
                                 MiningQueue.Enqueue(item);
                             }
                             stoppedMiners.Add(item);
                         }
                     }
                     //if a miner has stopped, we need to remove it from the running list as anyway it will be added once run
                     foreach (IMinerProgram item in stoppedMiners)
                     {
                         RunningMiners.Remove(item);
                     }
                 }
                 catch (Exception e)
                 {
                 }
             }
             else
             {
                 //Kill all running  miners and go to sleep for some time
                 for (int i = 0; i < RunningMiners.Count; i++)
                 {
                     IMinerProgram item = RunningMiners[i];
                     item.KillMiner();
                 }
                 RunningMiners.Clear();
             }
         }
         catch (Exception e)
         {
             Logger.Instance.LogError(e.Message);
         }
     }
     DecrThreadCount();
 }