public void Submit(Device aDevice, NeoScryptStratum.Work work, UInt32 aNonce)
        {
            if (Stopped)
            {
                return;
            }

            try  { mMutex.WaitOne(5000); } catch (Exception) { }

            ReportSubmittedShare(aDevice);
            try
            {
                String stringNonce = (String.Format("{3:x2}{2:x2}{1:x2}{0:x2}", ((aNonce >> 0) & 0xff), ((aNonce >> 8) & 0xff), ((aNonce >> 16) & 0xff), ((aNonce >> 24) & 0xff)));
                String message     = JsonConvert.SerializeObject(new Dictionary <string, Object> {
                    { "id", mJsonRPCMessageID },
                    { "method", "mining.submit" },
                    { "params", new List <string> {
                          Username,
                          work.Job.ID,
                          work.LocalExtranonceString,
                          work.Job.NTime,
                          stringNonce
                      } }
                });
                WriteLine(message);
                ++mJsonRPCMessageID;
            }
            catch (Exception ex) {
                Program.Logger("Failed to submit share: " + ex.Message + "\nReconnecting to the server...");
                Reconnect();
            }

            try  { mMutex.ReleaseMutex(); } catch (Exception) { }
        }
        public void workLoop()
        {
            // Wait for the first NeoScrypt to arrive.
            int elapsedTime = 0;

            while ((nscs.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)
                {
                    curWork = nscs.GetWork();                        // Get a new work item (can be for the same job).
                    neoScryptWorker.NewWork(curWork.Blob);
                }

                // let's do 20000 loops, 10ms delay each loop, should be less then 400s.  Then bail out if we get new orders from pool ofcourse.
                for (int i = 0; i < 20000; i++)
                {
                    if (stopped || (nscs.GetJob().Equals(curWork.Job) == false))
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(10);
                }
            }
        }