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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:58:31+00:00 2026-05-31T00:58:31+00:00

I have the following multithreaded program: class Program{ static void main(){ (new Thread(DoSomething)).Start(); }

  • 0

I have the following multithreaded program:

class Program{
  static void main(){
    (new Thread(DoSomething)).Start();
  }
  static void DoSomething(){
    // Dome something here...
  }
}

A couple of questions:

  1. Does the main thread exit after spinning off the child thread?
  2. If it does exit and the child thread is a background thread: Is the main process going to exit or will it wait for the background thread to finish?
  • 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-31T00:58:32+00:00Added an answer on May 31, 2026 at 12:58 am

    Typically, if you want to wait for the child thread to complete, you’d add a x.Join(); line (where x is the variable of your thread) wherever you want your main thread to stop and wait for the child to complete.

    EDIT: So, yes, the main thread will exit unless one of three cases occurs:
    a) the spawned thread completes before the rest of the main thread code (if you add any)

    b) You have a condition that waits for the thread to complete (such as the Join statement I mentioned, but there are other ways too).

    c) The main thread goes into a semi-infinite loop (such as a game/graphics engine).

    In your bare-bones example, it will exit for sure (given your question’s parameters, a background thread).

    EDIT2: Sorry, I seem to have dodged your second question (and actually only considered background threads the whole while). If it’s a background thread it will exit as I’ve explained, if it’s foreground then it shouldn’t (though I don’t have much experience with foreground threads, so I can’t say for sure).

    So to answer your questions: Yes, the main thread exits. Yes, if the child is specifically a background thread, the process will exit as well.

    EDIT3: Final edit, I promise. I just wanted to add some code so that you could prove the answer yourself (which is always nice to be able to do):

    static void Main(string[] args)
    {
        Thread thready = new Thread(DoSomething);
        thready.IsBackground = true;
        thready.Start();
    }
    
    static void DoSomething()
    {
        while (true)
        {
            Console.Write("thread's looping \n");
        }
    }
    

    By toggling the thready.IsBackground = true; to thready.IsBackground = false; you get a program that runs forever (not exiting until the thread does). Leaving it as true will exit very quickly.

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

Sidebar

Related Questions

I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have a multithreaded openCV program that uses 4 threads to do the following:
I have a simple multi-threaded program, with the following structure. public void someFunction() {
Suppose I have the following piece of code public synchronized void method() { if(something
I have a multithreaded application that runs using a custom thread pool class. The
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I'm very new to Python and multithreaded programming in general. Basically, I have a
Let's say I have a multithreaded C++ program that handles requests in the form
Situation: I have a multithreaded program written in C. If one of the threads
I have the following problem: Multithreaded WPF application, Model View Presenter Implementation. Presenters and

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.