public bool StartJob() { if (ThreadTestQueue.Count == 0) { return(false); } if (CommandQueue.Count == 0) { Console.WriteLine("All Start!!"); return(false); } Console.WriteLine("CommandQueue count :" + CommandQueue.Count); ThreadTest tt = ThreadTestQueue.Dequeue(); tt.Start(CommandQueue.Dequeue()); useThreadTest.Add(tt); Console.WriteLine("Thread Queue : " + ThreadTestQueue.Count); Console.WriteLine("Use Thread Queue : " + useThreadTest.Count); if (ReturnCheker.ThreadState == ThreadState.Unstarted) { ReturnCheker.Start(); } return(true); }
private void ReturnThread() { while (true) { int count = useThreadTest.Count; for (int i = 0; i < count; i++) { //Console.WriteLine(useThreadTest[i].state); if (useThreadTest[i] == null) { break; } if (useThreadTest[i].state == TestState.wait) { ThreadTest re = useThreadTest[i]; ThreadTestQueue.Enqueue(re); useThreadTest.RemoveAt(i); Console.WriteLine("Thread count : " + ThreadTestQueue.Count + ", Use Thread" + useThreadTest.Count); break; } } } }
public void SetThreadQueue(int num) { for (int i = 0; i < num; i++) { ThreadTest test = new ThreadTest(i); ThreadTestQueue.Enqueue(test); } Max_Count = num; ReturnCheker = new Thread(new ThreadStart(ReturnThread)); }