private void CreateRunner(Collection <Target> target, Collection <Parameter> param) { try { ManualResetEvent resetEvent = new ManualResetEvent(false); TextConsole console = new TextConsole(); //console.Show(); //ThreadStart consoleThreadStart = console.Show; //Thread consoleThread = new Thread(consoleThreadStart); //consoleThread.IsBackground = true; //consoleThread.Start(); doneEvents.Add(resetEvent); TargetRunner runner = new TargetRunner(target, param, null, resetEvent); targetRunners.AddItem(runner); ThreadPool.QueueUserWorkItem(runner.ThreadPoolCallback, targetRunners.Count - 1); //ThreadPool.SetMaxThreads(maxRunners, maxRunners); //WaitOrTimerCallback waitOrTimerCallback = runner.ThreadPoolCallback; //ThreadPool.RegisterWaitForSingleObject(resetEvent, waitOrTimerCallback, targetRunners, TEN_MINUTES, true); WaitHandle.WaitAny(doneEvents.ToArray()); //RemoveItemFromQueue(targetRunners.Count - 1); OnRemoveFromQueueEvent(runner, new RemoveFromQueueEventArgs(targetRunners.Count - 1)); } catch { } }
void RuntimeAllocator_RemoveFromQueueEvent(object sender, RemoveFromQueueEventArgs e) { try { lock (this) { int index = (int)e.State; TargetRunner runner = (TargetRunner)sender; //targetRunners.RemoveItem(targetRunners.ElementAt(index)); targetRunners.RemoveItem(runner); doneEvents.RemoveAt(index); } } catch { } }
private void CreateRunner(string target, string param) { try { ManualResetEvent resetEvent = new ManualResetEvent(false); doneEvents.Add(resetEvent); TargetRunner runner = new TargetRunner(target, param, resetEvent); targetRunners.AddItem(runner); //ThreadPool.QueueUserWorkItem(runner.ThreadPoolCallback, targetRunners.Count - 1); ThreadPool.SetMaxThreads(maxRunners, maxRunners); WaitOrTimerCallback waitOrTimerCallback = RemoveItemFromQueue; ThreadPool.RegisterWaitForSingleObject(resetEvent, waitOrTimerCallback, targetRunners, TEN_MINUTES, true); //WaitHandle.WaitAny(doneEvents.ToArray()); } catch { } }