Hi I am using the ADO.NET entity framework for the first time and the staticcode analysis is suggesting I change the following method to a static one as below.
My question is simple, is this thread safe?
public static void InsertUserDetails(UserAccount userAccount)
{
using (KnowledgeShareEntities entities = new KnowledgeShareEntities())
{
Users user = new Users();
user.usr_firstname = userAccount.FirstName;
user.usr_surname = userAccount.LastName;
user.usr_email = userAccount.Contact.Email;
user.usr_logon_name = userAccount.SAMUserAccountName.ToUpper();
user.usr_last_login_datetime = DateTime.Now;
entities.开发者_如何转开发AddToUsers(user);
entities.SaveChanges();
}
}
As you are using only local variables the method is thread safe. There are no static variables involved so everything will be on the thread local stack and no race conditions could occur.
精彩评论