0

If i start a thread like this

addingResults = new Thread(threadAddingResults);
addingResults.Start();

In the Form1_Load function the thread doesn't start but if i start it with the same code on a lets say button click it works fine. Any reason why this is going on? Is this intended behaviour?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vajura
  • 1,112
  • 7
  • 16
  • What does the thread do? It starts, but depending on what you have it do, the results are lost/not observed. – Marcel N. Aug 11 '14 at 06:21
  • 1
    Have you tried setting a breakpoint inside Form1_Load and threadAddingResults to check with the debugger? – DaveShaw Aug 11 '14 at 06:27
  • 1
    Where do you declare `addingResults`? if this is in the load event too then it will go out of scope very quickly – Sayse Aug 11 '14 at 06:33
  • @Sayse Why does that matter? – Sriram Sakthivel Aug 11 '14 at 06:36
  • @SriramSakthivel - The OP doesn't state what they are trying to do but it is possible that the thread is ending before having chance to finish (I don't believe that it "doesn't actualy start") – Sayse Aug 11 '14 at 06:37
  • @Sayse I can't understand your comment, what do you mean by *thread is ending before having chance to finish*? – Sriram Sakthivel Aug 11 '14 at 06:38
  • @SriramSakthivel - Finishing early? Finishing before the expected behaviour of the thread is completed – Sayse Aug 11 '14 at 06:39

1 Answers1

0

Found the error, i declared the thread as a variable outside and before i innitialized it i called addingResults.IsBackground for some reason no exception was returned in debug mode but the code after this in Form1_Load wasnt being executed.

So i just did this

addingResults = new Thread(threadAddingResults);
addingResults.IsBackground = true;
addingResults.Start();

And it works

Vajura
  • 1,112
  • 7
  • 16