public void Th_copy(TaskInfo[] masterplan) { //execute taskplan in separate thread //initialise stats DateTime start = DateTime.Now; TimeSpan elapsed; TimeSpan togo; //perform first read Th_read(masterplan[0]); autoEvents = new AutoResetEvent[] { new AutoResetEvent(false), new AutoResetEvent(false) }; //perform reads and writes parallel long x; for (x = 1; x < masterplan.LongLength; x++) { // ThreadPool.QueueUserWorkItem(new WaitCallback(Th_write), masterplan[x - 1]); //ThreadPool.QueueUserWorkItem(new WaitCallback(Th_read), masterplan[x]); //WaitHandle.WaitAll(autoEvents); var task1 = Task.Factory.StartNew(() => Th_write(masterplan[x - 1])); var task2 = Task.Factory.StartNew(() => Th_read(masterplan[x])); Task.WaitAll(task1, task2); if (halt1 || halt2) { break; } //update status elapsed = DateTime.Now.Subtract(start); togo = TimeSpan.FromTicks(elapsed.Ticks / (masterplan[x].y + 1) * (2048 - masterplan[x].y - 1)); string completed = Math.Round((double)(masterplan[x].y + 1) / 2048 * 100).ToString() + "%"; string speed1 = Math.Round((double)masterplan[x].src.nonces / 4096 * 2 * (masterplan[x].y + 1) * 60 / (elapsed.TotalSeconds + 1)).ToString() + " nonces/m "; string speed2 = "(" + (Math.Round((double)masterplan[x].src.nonces / (2 << 12) * (masterplan[x].y + 1) / (elapsed.TotalSeconds + 1))).ToString() + "MB/s)"; string speed = speed1 + speed2; lock (statusStrip) setStatus(masterplan[x].y + 1, "Completed: " + completed + ", Elapsed: " + TimeSpanToString(elapsed) + ", Remaining: " + TimeSpanToString(togo) + ", Speed: " + speed); } //perform last write if (!halt1 && !halt2) { Th_write(masterplan[masterplan.LongLength - 1]); } // close reader/writer masterplan[0].reader.Close(); masterplan[0].writer.Close(); if (halt1 || halt2) { setStatus(masterplan[x].y + 1, "Abort."); } //mark as finished if (!halt1 && !halt2) { BFS.SetStatus(masterplan[masterplan.LongLength - 1].drive, masterplan[masterplan.LongLength - 1].file, 1); } if (halt1 || halt2) { BFS.SetPos(masterplan[masterplan.LongLength - 1].drive, masterplan[masterplan.LongLength - 1].file, (uint)x); } if (!halt1 && !halt2) { setStatus(masterplan[masterplan.LongLength - 1].y + 1, "Completed."); } }