Close Windows Form while it is initializing
I have a winforms app that checks user credentials as it starts. If autharization fails I want to close the app. So I have been using the following
Public Sub New()
_CurrentUser.GetuserDetails
If _CurrentUser.IsAuthorized then
'Let the app start
Else
'Shut it down
Me.Close()
End IF
End Sub
However this produces 开发者_开发问答a "Cannot access a disposed object" error Any Ideas?
Instead of calling Me.Close(), call Application.Exit()
Thanks for the quick reply Jay Using Application.Exit certainly stopped the error occuring. Unfortunatly it didnt close the app either.:)
It did let me see that the next executed section was the Form_Load event so I moved all my authorization code to there and then Application.Exit worked a treat. Me.Close also worked fine in the Load block. Thanks again
加载中,请稍侯......
精彩评论