Threads inside a foreach loop in c#

前端 未结 8 1502
粉色の甜心
粉色の甜心 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条回答
  •  离开以前
    2021-01-01 00:07

    It would probably be better to structure your method like this:

    public void SendMails(DataTable dt)
    {
        foreach (DataRow row in dt.Rows)
        {
            // send emails
        }
    }
    

    And then call it like this:

    SendMails(dataTable);
    

    Or call the method with a BackgroundWorker so that your UI doesn't lock up.

提交回复
热议问题