A critical section is a higher level construct than a mutex. The current critical section wraps a semeaphore it uses for locking when it has to wait. Before it waits it will spin in user mode to avoid the costly transition to kernel mode and thread context switch.
You have two options to use a timeout with a critical section:
1. (Not recommended) Write a function that uses the internal LockSemaphore. You have to duplicate the functionality for EnterCriticalSection() but allow a timeout to be passed to the wait on the semaphore.
2. Spin on TryEnterCriticalSection. Use GetTickCount to check when you time out. Make sure you do this right. Read up on YieldProcessor, SwitchToThread and Sleep/SleepEx. This is only usefull if you _have to_ use a ctirical section and you _have to_ be able to timeout.
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
Can someone be helpful and show me a link or a piece of code that allows me to insert into my code so when the user clicks the X button at the top of the client so a message box appear and says "Are you sure you want to exit" along with the event.