Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applications not exiting properly?

Status
Not open for further replies.

WilliamUT

IS-IT--Management
Oct 8, 2002
182
US
Im having a problem with one of my applications not exiting when I close it down. When I pull up the task manager I can still see it running but the GUI is gone so it looks like it did shut down when in reality it did not. What could be causing this? What is the right way to terminate my applications?

Thanks
 
I have always used

Me.Close()

and never had a problem with it.

 
Yep,

Me.Close() is what you need.
In case there is a problem... use: Application.Exit()


-bclt

 
What is the startup object of the project? The application staying open after the GUI closes is usually because of a non-background thread that is still executing. A common reason for this is using a module as a start up object and loading the GUI from there. The GUI will run in a seperate thread (unless it is started with form.showdialog), and since the module thread is the primary application thread, the application will not end untill that thread ends.

You can throw Application.Exit(0) where ever you want to end the program, but you might first want to find out WHY it's not closing with the GUI.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
What is the sub that is run when the form is closing? is it the finalize one?
 
I figured out the closing events to a form.

Heres whats happening. When a button is pressed on the main form it hides the main form and loads another form. When I close the second form the program keeps running in the background.

I have also tried to show the main form when the second form is closing but it never becomes visible again and there ends up being no GUI at all...

any ideas?
 
Code:
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean


	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property


Add this in a region (or not) in form1 and exactly the same in form2l just replacing form1 with form2.


To hide form1: (code in form1 to hide itself and show form2)
Code:
		Form2.DefInstance.Show()
		Me.Hide()

To show form1 when form1 is closing:
Code:
	Private Sub Form2_[b]Closed[/b](ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
		Form1.DefInstance.Show()
	End Sub

This in bold could be also "Closing".


Hope helps
-bclt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top