private void ProcessLoadingQueue() { if (_loadQueue.Count > 0) // Task.Run(() => { ParallelUtils.While(() => _loadQueue.Count > 0 && (Surface != null && !Surface.Disposing && !Surface.IsDisposed), ProcessItem); }//); }
private void ProcessLoadQueueThread() { while (Surface != null && !Surface.Disposing && !Surface.IsDisposed) { ParallelUtils.While(() => concurrentDownloads < 6 && _loadQueue.Count > 0 && (Surface != null && !Surface.Disposing && !Surface.IsDisposed), ProcessItem); Thread.Sleep(50); } }
public static String Mine(Block lastBlock) { Staticnonce = 0L; String hash = CreateHash(lastBlock, Staticnonce); DateTime timestamp = DateTime.UtcNow; int difficulty = lastBlock.difficulty; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); ThreadPool.SetMaxThreads(0, 10); hash = CreateHash(lastBlock, 0); Func <bool> whileCondFn = () => !hash.StartsWith(string.Concat(Enumerable.Repeat("0", difficulty))); ParallelUtils.While(whileCondFn, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, (ParallelLoopState) => { lock (_object) { difficulty = AdjustDifficulty(lastBlock, timestamp, 3); timestamp = DateTime.UtcNow; Staticnonce += 1; hash = CreateHash(lastBlock, Staticnonce);; System.Diagnostics.Debug.WriteLine(hash + Staticnonce); System.Diagnostics.Debug.WriteLine(difficulty); //Console.WriteLine(whileCondFn()); if (hash.StartsWith(string.Concat(Enumerable.Repeat("0", difficulty)))) { Console.WriteLine("fdasfjkla;jsdfads" + hash); Console.WriteLine(Staticnonce); ActualHash = hash; ActualDiff = difficulty; //_Form1.richTextBox1.Invoke(new Action(() => _Form1.richTextBox1.Text += hash)); //BlockchainApp._Form1.update(hash); ActualNonce = Staticnonce; ParallelLoopState.Stop(); } } }); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); blocktime = elapsedTime; nonce = ActualNonce; return(ActualHash); }