-3

enter image description here

why the varialbe is 2 in the loop?

and it is the 1st breakpoint the program meet in the loop.

MethodMan
  • 18,625
  • 6
  • 34
  • 52
ArthurRen
  • 21
  • 2

1 Answers1

2

Because by the time your breakpoint was hit in the new thread, the main thread had already looped twice. Remember, they're running on separate threads, so unless you use some kind of synchronization mechanism, you won't be able to predict what occurs when.

rory.ap
  • 34,009
  • 10
  • 83
  • 174