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 8324233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:59:19+00:00 2026-06-08T23:59:19+00:00

class MultiThreading { public class ThreadClass { public string InputString { get; private set;

  • 0
class MultiThreading
{
    public class ThreadClass
    {
        public string InputString { get; private set; }
        public int StartPos { get; private set; }
        public List<SearchAlgorithm.CandidateStr> completeModels;
        public List<SearchAlgorithm.CandidateStr> partialModels;

        public ThreadClass(string s, int sPos)
        {
            InputString = s;
            StartPos = sPos;
            completeModels = new List<SearchAlgorithm.CandidateStr>();
            partialModels = new List<SearchAlgorithm.CandidateStr>();
        }

        public void Run(int strandID)
        {
            Thread t = new Thread(() => this._run(strandID));
            t.Start();
        }

        private void _run(int strandID)
        {
            SearchAlgorithm.SearchInOneDirection(strandID, ref this.completeModels, ref this.partialModels);
        }

        public static void CombineResult(
            List<ThreadClass> tc,
            out List<SearchAlgorithm.CandidateStr> combinedCompleteModels,
            out List<SearchAlgorithm.CandidateStr> combinedPartialModels)
        {
            // combine the result
        }
    }
}

class Program
    {

        static void Main(string s, int strandID)
        {
            int lenCutoff = 10000;
            if (s.Length > lenCutoff)
            {
                var threads = new List<MultiThreading.ThreadClass>();
                for (int i = 0; i <= s.Length; i += lenCutoff)
                {
                    threads.Add(new MultiThreading.ThreadClass(s.Substring(i, lenCutoff), i));
                    threads[threads.Count - 1].Run(strandID);
                }


                **// How can I wait till all thread in threads list to finish?**
            }
        }
    }

My question is how can I wait till all threads in “threads” list to finish and then do the call CombineResult method?

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-06-08T23:59:21+00:00Added an answer on June 8, 2026 at 11:59 pm

    Have ThreadClass expose a means to join the thread:

        private Thread nativeThread;
        public void Run(int strandID)
        {
            nativeThread = new Thread(() => this._run(strandID));
            nativeThread.Start();
        }
    
        public void Join()
        {
            nativeThread.Join();
        }
    

    And then use ThreadClass.Join on each thread after you start them:

        var threads = new List<ThreadClass>();
        for (int i = 0; i <= s.Length; i += lenCutoff)
        {
            threads.Add(new ThreadClass(s.Substring(i, lenCutoff), i));
            threads[threads.Count - 1].Run(strandID);
        }
    
        // Waits for each thread to finish in succession
        threads.ForEach(t => t.Join());
    

    Or, throw away your ThreadClass and enjoy System.Threading.Tasks:

    // e.g. class Models { Complete; Partial; }
    // private Models Search(string source, int offset, int length, int ID)
    var tasks = new List<Task<Models>>(
        from x in Enumerable.Range(0, s.Length / lenCutoff)
        select Task.Factory.StartNew<Models>(
            () => Search(s, x, lenCutoff, strandID));
    );
    
    // private Models CombineResults(IEnumerable<Models> results)
    var combine = Task.Factory.ContinueWhenAll<Models>(
        tasks.ToArray(),
        ts => CombineResults(ts.Select(t => t.Result)));
    
    combine.Wait();
    
    Models combinedModels = combine.Result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class X { int i; public: X() { i = 0; } void set(int
multithreading public class RaceData { public static void main(String[] args) { class UnsafeSequence implements
I added multithreading part to my code . public class ThreadClassSeqGroups { public Dictionary<string,
class Test { public static void main(String[] args) throws Exception { Test t =
class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
I have written this piece of code public class Test{ public static void main(String[]
I heave roughly speaking the following hierarchy class Base { public: virtual int value()
class Widget; std::vector< std::shared_ptr<Widget> > container class Criterium { public: bool operator()(const Widget& left,
Class 1 private void checkDuplicateCustomer(BulkCustomerVO bulkCustomerVO) { PagedDuplicateCustomerVO duplicateCustomerVO = new PagedDuplicateCustomerVO(); duplicateCustomerVO.setCustomer(bulkCustomerVO.getCustomerVO()); duplicateCustomerVO
class A{ virtual int foo1(int a){ return foo1_1(a,filler(a)); } template<typename FunctionPtr_filler> int foo1_1(int 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.