Solved

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

Posted on 2009-07-03
4
1,214 Views
Last Modified: 2013-12-17
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));

                        StoredProceduresData._1.Start();

                        StoredProceduresData._2.Start();

                        StoredProceduresData._30.Start();

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//....Wait  until to complete ALL 3 threads...

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                        

                       // StoredProceduresData.CallSpInsertColumns();

                        

                        _couponCounter = 0;

                    }

Open in new window

0
Comment
Question by:nikavak
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 24771416
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.
0
 
LVL 9

Expert Comment

by:Rahul Goel
ID: 24771417
You can use the BackgroundWorker Threads instread of normal threads, it will intimate you when it endns and what is progress.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24771424
Thread..::.Join Method

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

http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx


StoredProceduresData._1.Join();
StoredProceduresData._2.Join();
StoredProceduresData._30.Join();
0
 

Author Closing Comment

by:nikavak
ID: 31599515
Thanks a lot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now