Threads inside a foreach loop in c#

前端 未结 8 1545
粉色の甜心
粉色の甜心 2020-12-31 23:52

Hai guys,

I had the following code to send different mails to differnt users in my asp.net web application

foreach (DataRow dataRow in dataTable.Rows         


        
8条回答
  •  [愿得一人]
    2020-12-31 23:59

    Don't create your own threads, having 1000 threads will mean the CPU spending all it's time switching between them and very little time actually executing any work.

    Use the threadpool to do this, it will execute up to 25 (by default) background threads and can automatically block when they're all busy.

    See MSDN tutorial

提交回复
热议问题