I have a process that multiple users may call. It's a very expensive query, but it should only ever need to be run every 5 minutes or so to refresh some archive data. I have a lock right now so that we don't run the process several times at once, which would bring the system to it's knees, but each user then has to wait for the previous locks to run before they can run. If there are 3-4 users waiting for the lock, the 4th user has to wait upwards of 20 minutes for their query to run.
What I would like to do is to lock this object and run the query on the first request. If any other requests come in, have them wait for the current lock to finish, then return without actually executing the query.
Is there anything built into .Net that can accomplish this, or do I need to write some specific code for this lock?