开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜