In a module I have a sub main which is the start of my app

In this module I have declared an instance of my main form
Public MainForm as new frmMain
and in sub main I call it
MainForm.ShowDialog

I show it as dialog because if I just use Show, then it goes right through sub main and exits the application...

now while i think that in itself is odd, i used showdialog so the app will run while the main form is open. This works fine, but when the user clicks the X button, I set e.cancel = true because its just supposed to minimize to the system tray... but for some reason, even if I set cancel to true, the app then resumes in submain and exits the program....

any ideas?