I am designing an application and I am in a very early stage of the design process but I am hoping to get some advise on the best way forward. What I need is a mechanism that will control the close-down of an application. E.g before the application starts of its sets a flag in the db like a "critical section flag=true". If the user tries to close the application while the code is in this critical section the application will wait until "critical section flag=false" before it closes down. Any suggestions on the best design approach for this?