peispud
asked on
Gracefully force my application to close
Hi
I am using VB.Net 2005
See code below. I am trying to make this application completely stop (gracefully) in one click on Button2 no matter what my application is doing.
Thank you
I am using VB.Net 2005
See code below. I am trying to make this application completely stop (gracefully) in one click on Button2 no matter what my application is doing.
Thank you
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExitLoopTime As DateTime = DateTime.Now.AddSeconds(300)
Do While DateTime.Compare(ExitLoopTime, DateTime.Now) > 0
Application.DoEvents()
Loop
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
And the problem is ?
ASKER
Hi
The problem is that a person has to click twice to force the application to exit before the loop is complete. It's not a big deal, but that is not my intention. I wish to click Button2 just once and gracefully exit the application.
The problem is that a person has to click twice to force the application to exit before the loop is complete. It's not a big deal, but that is not my intention. I wish to click Button2 just once and gracefully exit the application.
ASKER
Oops... My mistake
If I click on button1 first, then I must click on button2 twice to exit the app.
If I click on button1 first, then I must click on button2 twice to exit the app.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Of course you are right and I am happy about that.
I've only recently begun to work with threads. I am beginning to see that they are very useful
Thanks!!!
I've only recently begun to work with threads. I am beginning to see that they are very useful
Thanks!!!
Glad I could help, and you should explore a little about threads or BackGroundWorker (that is an easy way to handle threads)