As far as I see you need to periodically poll for the last input time. When that last time is greater than 5 minutes, than you close the application. You can use a timer for this polling. You don't have to reset this timer, because is not a timer for the idle time, but a timer for the polling operation.

Is there anything that I'm missing here?