Reputation: 63
I am writing a vb.net application and am trying to close the application gracefully from the startup event if there are certain errors.
Is there a way to do this?
At the moment I have the "Enable Application Framework" checkbox selected, and all code is in the "Private Sub MyApplication_Startup(sender As Object, e As ApplicationServices.StartupEventArgs) Handles Me.Startup" event
Upvotes: 3
Views: 1777
Reputation: 61
The correct way to close during the Application.StartUp event is to set e.Cancel = True, since at that time there is no Form to Close nor a Application object to use Application.Exit
Upvotes: 4
Reputation: 63
I changed my strategy and removed the "Enable Application Framework" and changed to my startup object to Sub Main()
A brief example is:
Sub Main(byval args() as string) 'Do my checking here ... If MyCheckingFails then Return Application.Run(MyMainForm) End Sub
Upvotes: 0