I have an asp.net page that execute some update to db. The updates takes 2-3 seconds, all these hapends in a method that first read data from db and do some updates. When the page request are less then 2 sec for these action, the db read code, read the same state of records in db, and all update actions of asp.net page requests updates the same records.
How i can prevent these, that the newest request wait untill the oldest finish their execution?
Any ideas?
If I’m understanding you correctly, you want to block access to a particular set of methods until the process has been completed.
Easy enough… create a static method and implement a lock(). You can get real fancy with share locks, upgrades to read/write locks, etc… but the basic principal is that you lock your critical sections of shared code so other users cannot enter those sections.
http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.71).aspx
The lock keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock.