Close mainwindow automatically