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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:57:17+00:00 2026-05-26T14:57:17+00:00

I am using thread to start a public function of a class. The problem

  • 0

I am using thread to start a public function of a class. The problem is that only if set break point inside the thread function(public function of the class) it gets called otherwise calling the Thread.Start is not having any effect. Once the thread function is called it is completing successfully giving desired results.

 QueueProcessor     processor  = null;
 Thread subprocess =null;

 public void processQueue()
 {
    if (processor == null)
    {         
        processor = new QueueProcessor();
    }

    if (subprocess == null)
    {                                            
        subprocess = new Thread(processor.run);
        subprocess.IsBackground = true;
    }

    if (!subprocess.IsAlive)
    {                
        subprocess.Start();                                
    }
    else
    {          
    }
} 

class QueueProcessor
{       
    public QueueProcessor()
    {           
        instance = new RecordDao();
        service = new CommonsService();
    }

    public void run()
    {
        startProcessing(); // it won't reach here unless a breakpoint is set.
    }

    public bool startProcessing()
    {
        //some database routines here.

       // some web service calls here
    }
}

Please 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-26T14:57:18+00:00Added an answer on May 26, 2026 at 2:57 pm

    EDIT: Now that you’ve changed the code, there are two problems:

    1. You potentially try to restart a thread, if you ever call processQueue after the processing has finished. You can’t do that.

    2. If processQueue is called from multiple threads, you have issues of potentially starting multiple threads due to race conditions, and also memory model potential issues.

    The first point is more simply solved using:

    if (subprocess == null || !subprocess.IsAlive)
    {                                            
        subprocess = new Thread(processor.run);
        subprocess.IsBackground = true;
        subprocess.Start();
    }
    

    … but this still leaves the potential problem of the second point. What is calling processQueue? Is it always the same thread? (And why are you ignoring .NET naming conventions?)

    My guess is that what you’re seeing is actually the processing happening exactly once, but there being no work to do, and future calls not restarting the thread as presumably you expected – whereas if you have the breakpoint there, then by the time you hit “go” again, there’s work to do. At a guess… certainly starting a thread does work without breakpoints, so the flaw is somewhere in your code. If you could produce a short but complete program that demonstrates the problem, we could get to the bottom of it.


    Your thread does almost nothing, so it’s entirely reasonable for the thread to complete before it reaches the while loop. It’s not that it doesn’t start – it’s that it starts and then finishes immediately.

    Alternatively, you could have an execution flow like this:

    Main thread                  New thread status
    
                                 Not started...
    
    Check: IsAlive == false
    
                                 Still not started...
    
    Check: IsAlive == false
    
                                 Starting!
                                 Call startProcessing...
                                 startProcessing completes...
                                 Finished
    
    Check: IsAlive == false
    

    The thread has executed with no problems, but IsAlive is always false.

    It’s not clear why you have this code in the first place – what are you trying to achieve?

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

Sidebar

Related Questions

I want to start a new thread using a C function, not an objective-C
I have the main thread from which I start a window using invokeLater .
When a Thread is finished, you cannot run it once more, using start() method:
I am using vc++ and creating a thread using CreateThread function .Can I restart
I am using a thread to call a function containing a while loop to
I have a class SoundManager which contains a function called 'recordLoop'. In the constructor
Im using a gmail class so that my app can send me notification over
I am using multithreading in my C# code as follow: Thread startThread; public void
I am constructing several objects from a Class and using a particular function from
is it possible to spawn a new thread using a method that isn't static?

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.