Esempio n. 1
0
 void DownLoadingThread(object obj)
 {
     IncrThreadCount();
     while (m_keepRunning)
     {
         try
         {
             m_Downloading = false;
             if (DownloadingQueue.Count == 0 || m_keepMining == false)
             {
                 Thread.Sleep(3000);
             }
             else
             {
                 IMinerProgram miner = DownloadingQueue.Dequeue();
                 m_Downloading = true;
                 miner.DownloadProgram();
                 m_Downloading = false;
                 if (miner.ReadyForMining())
                 {
                     MiningQueue.Enqueue(miner);
                 }
             }
         }
         catch (ThreadAbortException e)
         {
             Logger.Instance.LogInfo("Downloading Thread has been stopped and will resume again!!");
             Thread.ResetAbort();
         }
         catch (Exception e)
         {
             Logger.Instance.LogError(e.Message);
             //if we feel the need to exit when there is an error in miner thread
             //m_keepRunning = false;
         }
         m_Downloading = false;
     }
     DecrThreadCount();
 }
Esempio n. 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();
 }