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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:14:13+00:00 2026-05-13T19:14:13+00:00

When myThread.Start(…) is called, do we have the assurance that the thread is started?

  • 0

When myThread.Start(…) is called, do we have the assurance that the thread is started? The MSDN documentation isn’t really specific about that. It says that the status of is changed to Running.

I am asking because I’ve seen a couple of times the following code. It creates a thread, starts it and then loop until the status become Running. Is that necessary to loop?

Thread t = new Thread(new ParameterizedThreadStart(data));
t.Start(data);
while (t.ThreadState != System.Threading.ThreadState.Running &&
       t.ThreadState != System.Threading.ThreadState.WaitSleepJoin)
{
     Thread.Sleep(10);
}

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-05-13T19:14:14+00:00Added an answer on May 13, 2026 at 7:14 pm

    If you’re set on not allowing your loop to continue until the thread has “started”, then it will depend on what exactly you mean by “started”. Does that mean that the thread has been created by the OS and signaled to run, but not necessarily that it’s done anything yet? Does that mean that it’s executed one or more operations?

    While it’s likely fine, your loop isn’t bulletproof, since it’s theoretically possible that the entire thread executes between the time you call Start and when you check the ThreadState; it’s also not a good idea to check the property directly twice.

    If you want to stick with checking the state, something like this would/could be more reliable:

    ThreadState state = t.ThreadState;
    
    while(state != ThreadState.Runnung && state != ThreadState.WaitSleepJoin)
    {
        Thread.Sleep(10:
    
        state = t.ThreadState;
    }
    

    However, this is still subject to the possibility of the thread starting, running, then stopping before you even get the chance to check. Yes, you could expand the scope of the if statement to include other states, but I would recommend using a WaitHandle to signal when the thread “starts”.

    ManualResetEvent signal;
    
    void foo()
    {
        Thread t = new Thread(new ParameterizedThreadStart(ThreadMethod));
    
        signal = new ManualResetEvent();
    
        t.Start(data);
    
        signal.WaitOne();
    
        /* code to execute after the thread has "started" */
    }
    
    void ThreadMethod(object foo)
    {
        signal.Set();
    
        /* do your work */
    }
    

    You still have the possiblity of the thread ending before you check, but you’re guaranteed to have that WaitHandle set once the thread starts. The call to WaitOne will block indefinitely until Set has been called on the WaitHandle.

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

Sidebar

Related Questions

If i have a thread something like this: Thread t = new Thread(myThread); t.start();
Or is it? I have a thread object from: Thread myThread = new Thread(pObject);
List<int> data=new List<int>(); foreach(int id in ids){ var myThread=new Thread(new ThreadStart(Work)); myThread.Start(id); } Work(){
In my OnCreate method I have created a thread that listens to incoming message!
Hey guys, I'm getting a really strange error. I have a program that needs
I have a Java Thread like the following: public class MyThread extends Thread {
I have a class with event method that would often be called. Let's say
I have a Qt application that launches two threads from the main thread at
Consider the following piece of code - class MyThread extends Thread { private int
i need to use my application class inside my thread which is started with

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.