在新线程中声明的局部变量的使用有什么不同吗?
string emailSubject = "New message notification";
string imagePath = somePath;
string conversationName = entity.Name;
new Thread(delegate()
{
foreach (var user in participantList)
{
string newEmailBody = emailBody.Replace("###ImagePath###", imagePath)
.Replace("###UserName###", user.Name)
.Replace("###ConversationName###", conversationName);
MailUtil.SendEmail(user.Email, emailSubject, newEmailBody);
}
}).Start();
在新线程中声明它们是否更安全?像这样:
new Thread(delegate()
{
string emailSubject = "New message notification";
string imagePath = somePath;
string conversationName = entity.Name;
foreach (var user in participantList)
{
string newEmailBody = emailBody.Replace("###ImagePath###", imagePath)
.Replace("###UserName###", user.Name)
.Replace("###ConversationName###", conversationName);
MailUtil.SendEmail(user.Email, emailSubject, newEmailBody);
}
}).Start();