Checkout the link:

How to find the user is trying to close the application using task manager or by pressing the X in Title bar, etc. How to restrict/refuse that