?
Solved

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

Posted on 2009-07-03
4
Medium Priority
?
1,226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 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 ITIL
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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 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