Take a look at the timer implemented in the openView() and closeView() calls of this sample:
openView()
closeView()