Why does the main thread's output come first in C#?

前端 未结 7 2199
半阙折子戏
半阙折子戏 2021-02-04 23:41

I wrote this little program:

class Program
{
    static void Main(string[] args)
    {
        Thread t = new Thread(WriteX);
        t.Start();

        for (in         


        
7条回答
  •  长情又很酷
    2021-02-05 00:02

    It basically needs time to start the thread up. You are running the thread code at the same time as the rest of the first method. So taking into account the time it takes to start the thread and then get to the point where it is writing the "." does that make sense?

    If you have a sort of reset button in your app to start everything again (without exiting) you may find that the first character is the "." because the thread will already exist.

提交回复
热议问题