private void numericUpDown1_ValueChanged(object sender, EventArgs e) { int count = 0; listBoxWork.Invoke((MethodInvoker)(() => count = listBoxWork.Items.Count)); if (count > numericUpDown1.Value) { NewThread thread = listBoxWork.Items[0] as NewThread; DeleteWorkingThread(thread); } else { ReleaseSemaphore(); /*object temp = 0; * do * { * listBoxWait.Invoke((MethodInvoker)(() => temp = listBoxWait.Items.Count)); * if ((int)temp > 0) * { * ReleaseSemaphore(); * } * } while (count > numericUpDown1.Value && (int)temp < 0);*/ } }
private void buttonCreate_Click(object sender, EventArgs e) { count++; NewThread thread = new NewThread(count, this); thread.Status = " new "; listBoxNew.Items.Add(thread); }
public void WorkWaitingThread(NewThread thread) { if (numericUpDown1.Value > listBoxWork.Items.Count) { listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.Items.Add(thread))); listBoxWait.Invoke((MethodInvoker)(() => listBoxWait.Items.Remove(thread))); } }
private void listBoxNew_DoubleClick(object sender, EventArgs e) { if (listBoxNew.SelectedItem != null) { NewThread thread = listBoxNew.SelectedItem as NewThread; thread.Status = "Wait"; listBoxWait.Invoke((MethodInvoker)(() => listBoxWait.Items.Add(thread))); listBoxNew.Invoke((MethodInvoker)(() => listBoxNew.Items.RemoveAt(listBoxNew.SelectedIndex))); thread.Start(); } }
private void listBoxWork_DoubleClick(object sender, EventArgs e) { int selectedIndex = 0; listBoxWork.Invoke((MethodInvoker)(() => selectedIndex = listBoxWork.SelectedIndex)); if (selectedIndex >= 0) { NewThread thread = listBoxWork.SelectedItem as NewThread; thread.StopThread = true; listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.Items.RemoveAt(selectedIndex))); } }
public void UpdateWorkingThread(NewThread thread) { int selectedIndex = 0; listBoxWork.Invoke((MethodInvoker)(() => selectedIndex = listBoxWork.SelectedIndex)); int index = 0; listBoxWork.Invoke((MethodInvoker)(() => index = listBoxWork.Items.IndexOf(thread))); if (index != -1 && index < listBoxWork.Items.Count) { listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.Items.Remove(thread))); if (index < listBoxWork.Items.Count) { listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.Items.Insert(index, thread))); } else { listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.Items.Add(thread))); } listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.SelectedIndex = selectedIndex)); } }
public void DeleteWorkingThread(NewThread thread) { listBoxWork.Invoke((MethodInvoker)(() => listBoxWork.Items.Remove(thread))); }