private void lbWorkingThreads_DoubleClick(object sender, EventArgs e) { if (lbWorkingThreads.SelectedItem != null) { ThreadWork workingThread = lbWorkingThreads.SelectedItem as ThreadWork; bsWorking.Remove(workingThread); workingThread.Stop(); } // when the working list has places we add new threads from the Waiting list if (bsWorking.Count - (int)nUDNumber.Value < 0) { AddThreadsToWorkingList(); } }
private void BalanceWorkingThreads() { if (previousNumber < (int)nUDNumber.Value) { if (bsWaiting.Count > 0) { // function that add threads to the working list AddThreadsToWorkingList(); } } else { if (bsWorking.Count > 0) { // find max to remove it ThreadWork threadWork = bsWorking.First(x => x.Count == bsWorking.Max(y => y.Count)); bsWorking.Remove(threadWork); threadWork.Stop(); } } // for checking previousNumber = (int)nUDNumber.Value; }
void OnDestroy() { _thread.Stop(); }