Is your app continously running in the forground, not allowing the device going in to sleep mode?
In that case a simple timer would do the job. You could initialize a timer with an interval of 60,000 (1 minute), set a global counter variable. In the timer_tick event count the counter up to 30, and then finish the program. You could reset the counter if something is done in the program so that it will not stop while you are busy with it.
Rolf