I am working on a project that runs several processes, each in its own thread. If I run every process at once I can get out of memory errors. What I would like to do is limit the running threads to say 2. I use the following to run each thread
Thread mythread = new Thread(new ThreadStart(this.MyFunction1));
mythread.IsBackground = true;
For this example heres what each thread does.
Start Thread 1 which displays text to textbox1
Start Thread 2 which displays text to textbox2
Start Thread 3 which displays text to textbox3
Start Thread 4 which displays text to textbox4
So if I limit it to 2 running theads it should run 1 and 2, then wait for one of those two threads to complete before proceeding to 3, then wait for a thread to complete again and continue with 4 and so on. However I do not want to lock the gui (not responding).
What I have tried is before each line putting a while TotalThreads<=MaxThreads loop but that locks the gui where if becomes unresponsive and goes all dim not responding. So I also tried putting that in a function and calling it as a different thread again and setting the background to false, but that did not wait.