I want to implement a multithread system (two threads will do) and I followed a tutorial
Thread t1 = new Thread(new ThreadStart(threadA));
Thread t2 = new Thread(new ThreadStart(threadB));
t1.Start();
t2.Start();
The output is unexpected for me as it shows:
“threadA”
“threadA”
“threadA”
“threadB”
“threadB”
“threadB”.
Is something wrong with my code? Many thanks.
This is happening because in the time that it takes for you to go from
t1.Start()tot2.Start(), yourt1has already completed.Try something like this if you want to see your code alternate a little
It should print something like this:
However, this just shows that you cannot guarantee any order when it comes to threading.