I have an ASP.NET Webform
application. I added a Ado.net Entity Data Model
for my database which has a table named GatewayProviders
. My table has 3 columns: Id(int), Description(string), GatewayType(int)
.
I added two methods in webform1.aspx.cs
:
public void update()
{
GatewayProvider gp = DB.GatewayProviders.Find(12);
gp.Description = "pejman";
DB.SaveChanges();
}
public void update2()
{
GatewayProvider gp = DB.GatewayProviders.Find(12);
gp.Description = "nazraz";
DB.SaveChanges();
}
I created a button named Button1
to webform1.aspx
and i added click-event
for button like this :
protected void Button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(update));
Thread th2 = new Thread(new ThreadStart(update2));
th.Start();
th2.Start();
}
assume i publish this application on web, then two client as the same time click on the button, my application give them error!! how can i fix it?
how can i make my code threadsafe
?