Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3439358
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:18:01+00:00 2026-05-18T08:18:01+00:00

below is my simple code to start 5 threads, each one calls a wcf

  • 0

below is my simple code to start 5 threads, each one calls a wcf service which returns the value sent in, my problem is that the :

public void clien_GetDataCompleted(object sender, GetDataCompletedEventArgs e)
        {
            lock (sync)
            {
                count += e.Result;
            }
        }

works ok and increments the count, but how do i capture when all the threads have completed, does anybody have simple example code on how to call multiple wcf services which use async methods.

public partial class Threading : Form
{
        public int count;
        ServiceReference1.Service1Client clien = new ServiceReference1.Service1Client();

        public Threading()
        {
            InitializeComponent();
        }

        private void GetData()
        {
            clien.GetDataAsync(1);
        }

        public void DisplayResults()
        {
            MessageBox.Show(count.ToString());
        }

        private object sync = new object();

        public void clien_GetDataCompleted(object sender, GetDataCompletedEventArgs e)
        {
            lock (sync)
            {
                count += e.Result;
            }
        }

        public List<Thread> RunThreads(int count, ThreadStart start)
        {
            List<Thread> list = new List<Thread>();
            for (int i = 0; i <= count - 1; i++)
            {
                dynamic thread = new Thread(start);
                thread.Start();
                list.Add(thread);
            }
            return list;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            clien.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(clien_GetDataCompleted);
            ThreadStart WcfCall = new ThreadStart(GetData);
            IList<Thread> threads = RunThreads(5, WcfCall);
        }

    }

many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:18:02+00:00Added an answer on May 18, 2026 at 8:18 am

    If you are using .NET 4.0 you can use Task Parallel Library (TPL) and use Tasks instead of Threads. Tasks has more flow control. What you can do with tasks something like

      // Wait for all the tasks to finish.
      Task.WaitAll(tasks);
    

    Here is example on how to use Tasks and wait for all tasks to finish. here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the code of a simple html with a table layout. In FF
I'm making a simple Image Debugger Visualizer. Code is below. I'm not sure if
I need a simple SQL to accomplish the below: Problem: When a petrol bunk
In below sample code, I use lambda function to make 3 threads doing different
Below is sample code to create a radio button element with Yes/No options in
In the below code sample, what does {0:X2} mean? This is from the reflection
The code below shows a sample that I've used recently to explain the different
The simple demo below captures what I am trying to do. In the real
Below I have a very simple example of what I'm trying to do. I
Simple enough question, I just need to break through one minimal wall of confusion.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.