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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:31:34+00:00 2026-05-27T12:31:34+00:00

Main question is: How to run the code within TestingButton_Click on several threads in

  • 0

Main question is: How to run the code within TestingButton_Click on several threads in background (similar to BackgroundWorker) so I will be able to:
1. Get all the raw data to the methods
2. Cancel test for all threads simultaneously
3. Report progress
4. Retrieve all the result tables to main thread.

The following code is within TestingButton_Click

List<Thread> threads = new List<Thread>();

            //Testing for each pair
            foreach (InterfaceWithClassName aCompound in Group1)
            {
                foreach (InterfaceWithClassName bCompound in Group2)
                {
                    InstancePair pair = new InstancePair();
                    //some code

                    if (testModeParallel)
                    {
                        Thread thr = new Thread(TestPairParallel);
                        thr.Start(pair);
                        threads.Add(thr);
                    }

                    else
                    {
                        Thread thr = new Thread(TestPairSerial);
                        thr.Start(pair);
                        threads.Add(thr);
                    }
                }
            }              

            while (true)
            {
                int i = 0;

                foreach (Thread thread in threads)
                {
                    if (thread.IsAlive)
                        break;

                    i++;
                }

                if (i == threads.Count)
                    break;

                Thread.Sleep(1000);
            }
            pairsResultsDataGrid.ItemsSource = tab.DefaultView

User is able to choose what compounds to test so every time I have different number of pairs to test.
I made to different methods TestPairSerial() and TestPairParallel() just in case.

TestPairSerial() structure is

        do
        {
            do
            {

            } while (isSetbCompaundParams);

        } while (isSetaCompaundParams);

        //filling up results into tables (main window variables) later to be connected to DataGrids

TestPairParallel() is implemented with InfinitePartitioner and using similar structure only with Parallel.ForEach(new InfinitePartitioner(),…

Thank you for your help.

  • 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-27T12:31:35+00:00Added an answer on May 27, 2026 at 12:31 pm

    How to run the code within TestingButton_Click on several threads in
    background.

    I would use a Task as they were design to do exactly what you want.

    The only other question I will answer until you get closer to the actual solution is the following:

    Report progress

    There are lots of ways to report the progress on a given thread, you would have to subscribe to an event, and write code to report the progress of the thread. In order to update a control on the form, this would require you Invoke the change, this is not a trivial feature.

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

Sidebar

Related Questions

first of all, my main question: What are some good troubleshooting techniques when you
When I run the following code, int x[4096]; int *y; int *m; void main()
If you build and run the code, you will see it doesn't work properly.This
My main question is given a feature centroid, how can I draw it in
The title is the main question. The exact scenario (I am 'using namespace std;'):
This was the main question posed by Greg Wilson's bits of evidence presentation. I'm
I am using Struts2, Spring 2 and Junit 4.5. My main question is, whether
Quick question, is there a way to call your main method whatever you like
I asked a question yesterday which got answers but didnt answer the main point.
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,

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.