I have a service which executes a lengthy process once a day. A timer executes every minute and performs a check to see if this process is due to be run. Only after the process completes successfullly does it mark a variable such that subsequent timers simply return.

So the question is, what is the best way to ensure this lengthy process is called only once. If it takes 3 minutes to complete and the timer is running once a minute, up to three calls to the lengthy process could be made.

The lengthy process needs only to be run once, thus its not a matter of using typical thread synchronization where the other timers need to wait for the first to return. Essentially a boolean can be kept to mark the lengthy process as running. Calls to the lengthy process could simply return if this boolean is flagged.

The real question is, what is the best way to accomplishing this?

PS: this is more a question out of professional curiousity rather than something I'm stuck on. I'm just curious about the best practice for this scenario. In reality I decided to mark the variable whether the process fails or succeeds.

Cheers,
Chris