How to run two threads parallel?

后端 未结 4 991
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 15:20

I start two threads with a button click and each thread invokes a separate routine and each routine will print thread name and value of i.

Program runs

4条回答
  •  被撕碎了的回忆
    2020-12-24 15:47

    They run parallel, but start with a time delay that is bigger than the runtime of each thread itself. Toss in a delay after each Console.WriteLine and you'll see.

    By the way, the more elegant way of starting a new thread is

    ThreadPool.QueueUserWorkItem(delegate
    {
        //code here
    });
    

提交回复
热议问题