C# Threading/Lock confusion

后端 未结 3 1498
轮回少年
轮回少年 2021-01-05 11:28

I have the following code:

var items = new List {\"1\", \"2\", \"3\"}; // 200 items
foreach(var item in items) {
  ThreadPool.QueueUserWorkItem         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 11:34

    The following note from MSDN documentation on ThreadPool says it all:

    The threads in the managed thread pool are background threads. That is, their IsBackground properties are true. This means that a ThreadPool thread will not keep an application running after all foreground threads have exited.

    Your application simply exits (by reaching end of Main) before your threads finish running.

提交回复
热议问题