C# framework 3.5:how wait multiple threads to complete?

C# framework 3.5:how wait multiple threads to complete?for example I have three threads and I want to wait to complete all (3 threads);
if (_couponCounter >= Constants.PacketProcessedcoupons || NoCouponFound == true)
                        StoredProceduresData._1 = new Thread(new   ThreadStart(StoredProceduresData.CallSpInsertColumns_1));
                        StoredProceduresData._2 = new Thread(new ThreadStart(StoredProceduresData.CallSpInsertColumns_1));
                        StoredProceduresData._30 = new Thread(new ThreadStart(StoredProceduresData.CallSpInsertColumns_1));
//....Wait  until to complete ALL 3 threads...
                       // StoredProceduresData.CallSpInsertColumns();
                        _couponCounter = 0;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A way to solve it:
1. Create and start the threads. Each thread increments a synchronized global thread counter.

2. Have each thread signal that is is finished by decrementing the global counter.

3. Put the main process on a timer that periodically tests the counter, and idles the rest of the time. When the count gets to zero, take the next action.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rahul Goel ITILSenior Consultant - DeloitteCommented:
You can use the BackgroundWorker Threads instread of normal threads, it will intimate you when it endns and what is progress.
Thread..::.Join Method

Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping.


nikavakAuthor Commented:
Thanks a lot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.