What I have is a web service that can take up to hundreds of hits per second at times on a quad core dedicated server running IIS7.
This web service does it's thing and as part of it's process has a cache object with a filesystem dependency. When the cache expires (about 15 seconds on average), I use that as a trigger to fire a separate thread off to execute an external routine that I don't want to block the normal request that came in and triggered it in the first place.
What I need is to ensure that this thread only gets called once before it completes. For instance, when my cache object expires, the webservice is taking so many hits that sometimes it can get several hits before the cache object is re-generated, which means the code that creates the thread can get called several times concurrently as well. I only want it to get called once (until it completes) because there is no reason to have concurrent threads executing this routine, ever....
For now I have a Boolean variable that is set to false right before the code that creates my new thread. When the thread completes and hits the callback, that variable is reset to true, letting me know that the thread has completed it's work and is good to be executed again, next cycle around.
I'm not sure this is the best way to accomplish what I'm wanting to do - is there a better way to ensure that only one of these threads is ever run at one given time?
This web service does it's thing and as part of it's process has a cache object with a filesystem dependency. When the cache expires (about 15 seconds on average), I use that as a trigger to fire a separate thread off to execute an external routine that I don't want to block the normal request that came in and triggered it in the first place.
What I need is to ensure that this thread only gets called once before it completes. For instance, when my cache object expires, the webservice is taking so many hits that sometimes it can get several hits before the cache object is re-generated, which means the code that creates the thread can get called several times concurrently as well. I only want it to get called once (until it completes) because there is no reason to have concurrent threads executing this routine, ever....
For now I have a Boolean variable that is set to false right before the code that creates my new thread. When the thread completes and hits the callback, that variable is reset to true, letting me know that the thread has completed it's work and is good to be executed again, next cycle around.
I'm not sure this is the best way to accomplish what I'm wanting to do - is there a better way to ensure that only one of these threads is ever run at one given time?