private void buttonCreate_Click(object sender, EventArgs e) { if (numericUpDown.Value != 0) { _count++; MyThread thread = new MyThread(this, _count); thread.State = "created"; listBoxCreated.Items.Add(thread); } }
private void listBoxCreated_MouseDoubleClick(object sender, MouseEventArgs e) { if (listBoxCreated.SelectedItem != null) { if (listBoxWorking.Items.Count == 0) { _semaphore = new Semaphore((int)numericUpDown.Value, (int)numericUpDown.Value); } MyThread thread = listBoxCreated.SelectedItem as MyThread; thread.State = "waiting"; listBoxWaiting.Invoke((MethodInvoker)(() => listBoxWaiting.Items.Add(thread))); listBoxWaiting.Invoke((MethodInvoker)(() => listBoxCreated.Items.RemoveAt(listBoxCreated.SelectedIndex))); thread.Start(); } }
public void RemoveWorkingThread(MyThread thread) { listBoxWorking.Invoke((MethodInvoker)(() => listBoxWorking.Items.Remove(thread))); }