Example #1
0
        public void workLoop()
        {
            // Wait for the first PascalJob to arrive.
            int elapsedTime = 0;

            while ((kcs.GetJob() == null) && !stopped)
            {
                System.Threading.Thread.Sleep(100);
                elapsedTime += 100;
                if (elapsedTime >= 5000)
                {
                    Program.Logger("Waiting for job from pool...\n");
                    elapsedTime = 0;
                }
            }



            while (!stopped)
            {
                // Each time pascalWork.Blob gives a different blob for the same work, so this is how we get more 32bit nonce search areas...
                // Just have to rerun this loop at a higher rate then we run out of work nonces...
                // For now let's make sure we call this at least every 2s, that means we can support hash speeds up to 2GH/s .
                // Callback will be asyncrhonus, so have to lock cur and pre work while updating them.
                lock (this)
                {
                    prevWork = curWork;                             // remember the old work item in case the miner reports finished work on it, we can still hand them in (if the job is the same).
                    curWork  = kcs.GetWork();                       // Get a new work item (can be for the same job).
                    keccakWorker.NewWork(curWork.Blob);
                }

                // let's do 200 loops, 10ms delay each loop, should be less then 4s.  Then bail out if we get new orders from pool ofcourse.
                //for (int i = 0; i < 200; i++)
                for (int i = 0; i < 200; i++)
                {
                    if (stopped || (kcs.GetJob().Equals(curWork.Job) == false))
                    {
                        Console.WriteLine("DEBUG - BREAK TO GIVE NEW POOL JOB");
                        break;
                    }
                    System.Threading.Thread.Sleep(10);
                }
            }
        }