-
January 24th, 2013, 10:55 AM
#1
Controlling Thread Count without locking the GUI
Hi All,
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
RunningThreads++;
Thread mythread = new Thread(new ThreadStart(this.MyFunction1));
mythread.IsBackground = true;
mythread.Start();
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.
Any ideas would be much appreciated.
Thanks
-
January 24th, 2013, 02:29 PM
#2
Re: Controlling Thread Count without locking the GUI
Got this working using Application.DoEvents(); in a loop
-
January 24th, 2013, 10:37 PM
#3
Re: Controlling Thread Count without locking the GUI
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
February 3rd, 2013, 03:55 PM
#4
Re: Controlling Thread Count without locking the GUI
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|