Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: Now that you've changed the code, there are two problems:</p> <ol> <li><p>You potentially try to <em>restart</em> a thread, if you ever call <code>processQueue</code> after the processing has finished. You can't do that.</p></li> <li><p>If <code>processQueue</code> is called from multiple threads, you have issues of potentially starting multiple threads due to race conditions, and also memory model potential issues.</p></li> </ol> <p>The first point is more simply solved using:</p> <pre><code>if (subprocess == null || !subprocess.IsAlive) { subprocess = new Thread(processor.run); subprocess.IsBackground = true; subprocess.Start(); } </code></pre> <p>... but this still leaves the potential problem of the second point. What is calling <code>processQueue</code>? Is it always the same thread? (And why are you ignoring .NET naming conventions?)</p> <p>My guess is that what you're seeing is <em>actually</em> 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 <em>does</em> work without breakpoints, so the flaw is somewhere in your code. If you could produce a short but <em>complete</em> program that demonstrates the problem, we could get to the bottom of it.</p> <hr> <p>Your thread does almost nothing, so it's entirely reasonable for the thread to complete before it reaches the <code>while</code> loop. It's not that it doesn't start - it's that it starts and then finishes immediately.</p> <p>Alternatively, you could have an execution flow like this:</p> <pre><code>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 </code></pre> <p>The thread has executed with no problems, but <code>IsAlive</code> is always false.</p> <p>It's not clear <em>why</em> you have this code in the first place - what are you trying to achieve?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload