Why are you adding this code to your main routine instead of your MainWindow class?