I having problem managed thread parallel in console application.
I am running 10 threads parallel & all thread doing some specific task.
In case if any task is over/completed then doing stop/end thread and immediate I started new thread instance.
I want 10 threads so anyone thread is going to stop/end then It generates new thread.
but every time I want 10 threads in running mode in console application &
It should be parallel work using C# console application.
How I can running 10 threads in C# console application?
I having problem managed thread parallel in console application. I am running 10 threads
Share
At the end of each thread put a lock on some shared object (lock (obj) {}).
Then remove the current thread from a collection of threads you have.
If the collection.Count is less than 10 create a new one and put inside the collection.
Release the lock.
Be sure to catch all exception inside the thread or you code will fail when a thread exception happens. That is make sure that the lock part of the code is always called (except on a Thread abord exception but that will not matter).
But as stated I think you should use a ThreadPool for such a task…