C# multi-threaded console application - Console quits before threads complete

后端 未结 6 1132
感动是毒
感动是毒 2021-02-08 23:14

I have a c# console application that creates up to 5 threads.

The threads are executing fine, but the UI thread shuts down as it finishes its work.

Is there a

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 00:00

    Ah - the ThreadPool is background. It is queued, but then your program ends. Finished. Program terminates.

    Read up on Semaphores (WaitSignal) and wait- The threads in the callback at the end signal they are ended, when all have signaled that the main thread can continue.

提交回复
热议问题