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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:04:30+00:00 2026-05-23T07:04:30+00:00

Nutshell: I launch a thread from my form, then some time later use the

  • 0

Nutshell: I launch a thread from my form, then some time later use the Join method on it. It terminates but my application is stuck on the Join and refuses to acknowledge that it’s done joining. What would cause this to happen? My thread is launched from a button on my form, and attempts to join from a second button on the same form.

More Info:
I have an application that uses threading to accomplish communications and number crunching. Assuming the Main Form to be the parent thread, the first child is Child1. Upon starting Child1 establishes some communications with external devices and launches 2 child threads of its own (Child2 and Child3) to process the incoming data.

When the user decides that the application is to stop processing incoming data I need Child1 to terminate (so com settings can be altered prior to resuming, if necessary). I set a stop event and Child1 exits its execution loop, the first things it does is notify Child2 and Child3 that they are no longer needed (via another stop event), Child2 and Child3 are waited for with the Join method within Child1. This works just fine.

What does not work is that the form also uses the Join method on Child1 after setting the stop event that prompted Child1 to exit it’s run loop and terminate, this Join, however, waits indefinitely.

Stepping Through: When I step through my app I notice that at the moment before using Join the IsAlive property is true. After I hit Child1.Join() I can no longer get any information from the thread because it’s in “JoinWaitSleep”. However, if I run a while loop that causes the form thread to sleep while Child1.IsAlive is true, this works just fine. Is my second button somehow part of a thread that cannot join Child1 to it?


public void Run()
{   //Known as Child1
    //code to setup coms is here

    //Launch Builder threads
    InsertBackgroundMonitor("Launching Collector Threads");
    RunBuilders = true;

    //Known as Child2 and Child3
    BuildThread1 = new Thread(new ThreadStart(Cam1Builder));
    BuildThread2 = new Thread(new ThreadStart(Cam2Builder));
    BuildThread1.Start();
    BuildThread2.Start();

    while (!StopEventHandle.WaitOne(0, true))
    {
    //// Code that waits for coms and tosses data into lists
    }

    RunBuilders = false;

    //Wait for threads to terminate
    BuildThread1.Join();
    BuildThread2.Join();
}

private void RunButton_Click(object sender, System.EventArgs e)
{
    //Button for running the control thread
    ControlThread = new Thread(new ThreadStart(Run));
    ControlThread.Start();
}

private void StopButton_Click(object sender, System.EventArgs e)
{
    if (btnStop.Enabled)
    {   //Button for stopping the control thread
        StopEventHandle.Set();

        if (ControlThread != null)
        {
            while (ControlThread.IsAlive)
            {
                Thread.Sleep(100);
            }
            //somehow Join did not work
            //ControlThread.Join();
        }

        //Update buttons
        btnStart.Enabled = true;
        btnStop.Enabled = false;               
    }
}
  • 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-23T07:04:31+00:00Added an answer on May 23, 2026 at 7:04 am

    It’s difficult to say without more code, but you have SOME resource that you’ve started that you’re not properly shutting down.

    Join() waits for the thread to be completely shut down, and all resources released before returning. If the Thread has any BackgroundWorker tasks, or if it has any spare tasks that you aren’t showing still running it will not return.

    Since both of the BuildThread1 and BuildThread2 are returning correctly, and Join’ing, you can be sure it’s not one of those, or anything that they’re doing. Look over the rest of the code. What does it do?

    EDIT:
    This works fine:

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
    
        Thread ControlThread;
        Thread BuildThread1;
        Thread BuildThread2;
        volatile bool RunBuilders = true;
        volatile bool RunControl = true;
    
        private void button1_Click(object sender, EventArgs e)
        {
            ControlThread = new Thread(new ThreadStart(Run));
            ControlThread.Start();
        }
    
        private void button2_Click(object sender, EventArgs e)
        {
            RunControl = false;
    
            if (ControlThread != null)
            {
                while (ControlThread.IsAlive)
                {
                    Thread.Sleep(100);
                }
                //somehow Join did not work
                ControlThread.Join();
            }
        }
    
        public void Run()
        {   //Known as Child1
            //code to setup coms is here
    
            //Launch Builder threads
            RunBuilders = true;
    
            //Known as Child2 and Child3
            BuildThread1 = new Thread(new ThreadStart(Cam1Builder));
            BuildThread2 = new Thread(new ThreadStart(Cam1Builder));
            BuildThread1.Start();
            BuildThread2.Start();
    
            while (RunControl)
            {
            //// Code that waits for coms and tosses data into lists
            }
    
            RunBuilders = false;
    
            //Wait for threads to terminate
            BuildThread1.Join();
            BuildThread2.Join();
        }
    
    
        public void Cam1Builder()
        {
            while ( RunBuilders )
            {
    
            }
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a nutshell: Using jquery I want to get some xml output and use
Here are the specs that I'm trying to implement in a nutshell: 1) Some
I'm looking for some help with a dependency issue. In a nutshell, I've included
In a nutshell, there's a global stylesheet: a { font-family: Arial; } I want
In a nutshell: I want to do the same thing Dependency Walker does. Is
I was reading Algorithms in a Nutshell (O'Reilly) and came across this symbol in
Here's what I've been trying to do, in a nutshell: class example <T extends
OK, I have a somewhat complicated system in C++. In a nutshell, I need
In a nutshell: how do I access the methods of a class that is
In a nutshell on page1.php I have a calculator that consists of an HTML

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.