I’m new to C# and have a this problem:
I have an .aspx page that accepts a parameter eventId.
On the first time this page is requested with a specific eventId, I need to insert some rows into the database that are unique to that event.
All other times that the page is requested with that eventId, no rows should be inserted.
I can query the database to see if those rows already exist for that event, but this will not prevent issues of concurrency.
Say, 2 clients requested that page with eventId = 7 exactly at the same time – rows for that event might be inserted twice.
How can I use a Mutex/Lock/Monitor or anything else to avoid that?
I need the locking mechanism to be identified by a string – the event id
Thanks in advance…
in your db create a unique index based on event id. on your asp page always insert and handle the case where the insert fails. if the insert fails the event id has already been used by someone else. in this design the db does the synchronization.