Using End

B

Bob

My app shows a modal MDI parent form, and creates a timer that ticks every
ten minutes to boot unresposive users at 3 in the morning. Below is a
simplified working example with no time check. My question is, is it OK to
use End or it is there a cleaner way to close the app? Keep in mind that I
want everything taken down, including any warning dialogue box shown from
the timer, and any others that happen to be still open in the MDI parent
itself - so frm.Close does not work.

TIA,
Bob

'---------------------------------
Module Main

Private WithEvents tmr As Windows.Forms.Timer
Private frm As Form

Public Sub Main()
tmr = New Timer
tmr.Interval = 2000
tmr.Enabled = True
frm = New Form
frm.WindowState = FormWindowState.Maximized
frm.IsMdiContainer = True
frm.ShowDialog()
End Sub

Private DoingMessage As Boolean

Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tmr.Tick
If DoingMessage Then
Beep()
End
Else
Dim msg As String = "This application will now shut down for the
night."
DoingMessage = True
If MsgBox(msg, MsgBoxStyle.OKCancel) = MsgBoxResult.OK Then
End
End If
DoingMessage = False
End If
End Sub

End Module
 
L

Larry Serflaten

Bob said:
My app shows a modal MDI parent form, and creates a timer that ticks every
ten minutes to boot unresposive users at 3 in the morning. Below is a
simplified working example with no time check. My question is, is it OK to
use End or it is there a cleaner way to close the app? Keep in mind that I
want everything taken down, including any warning dialogue box shown from
the timer, and any others that happen to be still open in the MDI parent
itself - so frm.Close does not work.

It could work, if you designed it to work....

You could create a class whose sole responsibility is to raise a ShutDown
event and have all your forms listen for that event and close themselves down
(gracefully) when it happens. It may mean you have to create your own
MessageBox to display messages, but the 15 minutes you might use to do
that will provide you with a proactive means to be sure everything closes.
(Be aware you may not know which order the individual forms will recieve
that ShutDown event notification, so each form should just handle shutting
themselves down)

Instead of calling End, you could just send a call to that class to raise
the ShutDown event, and then exit out of the current sub. With all forms
closed, and no code executing, your application should close in a nice
clean fashion.

LFS
 
H

Herfried K. Wagner [MVP]

Rulin Hong said:
I will use Application.Exit Method.

This method will work similar to 'End'. I would try to avoid using both of
these methods and close the main form instead.
 
B

Bob

Larry Serflaten said:
It could work, if you designed it to work....

You could create a class whose sole responsibility is to raise a ShutDown
event and have all your forms listen for that event and close themselves down
(gracefully) when it happens. It may mean you have to create your own
MessageBox to display messages, but the 15 minutes you might use to do
that will provide you with a proactive means to be sure everything closes.
(Be aware you may not know which order the individual forms will recieve
that ShutDown event notification, so each form should just handle shutting
themselves down)

Instead of calling End, you could just send a call to that class to raise
the ShutDown event, and then exit out of the current sub. With all forms
closed, and no code executing, your application should close in a nice
clean fashion.

LFS

Um... hmmm.

Yes, even though it's 130MB of code (most of it forms designer bloat) with
both inputboxes and messageboxes, I suppose it wouldn't take too long to
search and replace all of these.

I just have to shake my head, though, I would have thought MS would have put
in a facility to close all an app's dialogues automatically by now. *shrug*

I think I'm going to dig around for a way to detect and kill all dialogues
first (exluding the main MDI form of course). I bet there's a way.

Bob
 
J

jela

environment.exit

Never failed me before.

Is it nice ? Probably not.
Does it kill everything? Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top