|
-
Apr 17th, 2013, 09:38 AM
#1
Please explain why these are two 'No No !' commands.
Hi, in recent days, I've been admonished for using two commands: 'My.Application.DoEvents' and 'End'.
If they are so bad why are they still available?
Ok... I have a project, at the end of which, or if there's a user error; I want to display a short message and close the program. I do not want to use a MessageBox because I just want the program to close down, on it's own after just five seconds without intervention from the user... No buttons.
I'm not bothered that everything is put on hold for those five seconds because this program only runs once as a 'Start Up' program, and five seconds is a drop in the ocean these days compared to the time it takes my machine to boot-up.
'No No' 1: The process has to be able to 'see' the Timer1.Tick so I call: My.Application.DoEvents() while it waits.
'No No' 2: When the timer 'ticks' Timer1 is disabled and the While Loop completes... Fine, so what's next? Me.Close(), close the program: Right ? Does the program close? NO... It just carries on as if nothing had said Stop. So... I add the second 'No No': End... Problem solved.
Where's the harm ? What's so tragic ?
vb.net Code:
Private Sub Timer1_Tick() Handles Timer1.Tick
Timer1.Enabled = False
End Sub
Private Sub All_Done(ByVal err As Boolean)
Timer1.Enabled = True
If err Then Label2.Visible = True
While Timer1.Enabled
My.Application.DoEvents()
End While
Me.Close()
End
End Sub
Poppa.
Along with the sunshine there has to be a little rain sometime.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|