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

  • Home
  • SEARCH
  • 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 698323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:15:44+00:00 2026-05-14T03:15:44+00:00

Greetings I have a program that creates multiples instances of a class, runs the

  • 0

Greetings

I have a program that creates multiples instances of a class, runs the same long-running Update method on all instances and waits for completion. I’m following Kev’s approach from this question of adding the Update to ThreadPool.QueueUserWorkItem.

In the main prog., I’m sleeping for a few minutes and checking a Boolean in the last child to see if done

while(!child[child.Length-1].isFinished) {
    Thread.Sleep(...);
}

This solution is working the way I want, but is there a better way to do this? Both for the independent instances and checking if all work is done.

Thanks

UPDATE:
There doesn’t need to be locking. The different instances each have a different web service url they request from, and do similar work on the response. They’re all doing their own thing.

  • 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-14T03:15:44+00:00Added an answer on May 14, 2026 at 3:15 am

    If you know the number of operations that will be performed, use a countdown and an event:

    Activity[] activities = GetActivities();
    int remaining = activities.Length;
    using (ManualResetEvent finishedEvent = new ManualResetEvent(false))
    {
        foreach (Activity activity in activities)
        {
            ThreadPool.QueueUserWorkItem(s =>
            {
                activity.Run();
                if (Interlocked.Decrement(ref remaining) == 0)
                    finishedEvent.Set();
            });
        }
        finishedEvent.WaitOne();
    }
    

    Don’t poll for completion. The .NET Framework (and the Windows OS in general) has a number of threading primitives specifically designed to prevent the need for spinlocks, and a polling loop with Sleep is really just a slow spinlock.

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

Sidebar

Related Questions

Greetings all, I’m working on a C# program that requires being able to get
greetings all i have a domain class named car and i have an object
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
Greetings! I have an XML value that I'd like to use as a boolean
Greetings, Apologies in advance that I have not researched this toughly enough to answer
Greetings, Forum. I'm working on a program in Python that uses Twisted to manage
i have created a music greetings application in iphone. I want that when a
Greetings, fellow StackOverFlow members. I have just begun to learn how to program web-enabled
Greetings! I have a solution in VS2010 that defines 3-4 individual applications. These 3-4
Greetings! I have an issue here that i can't find. I am getting a

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.