How to do a task when app is closed?

I want to run a procedure when app is closed .
After every 10 minutes ?

Check this extension