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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't close my application 2

Status
Not open for further replies.

colinb

Programmer
Mar 26, 2001
10
GB
I have written a small VB.NET application that accesses an mdb database and then dynamically creates controls based upon it's values. A timer runs and refreshes the screen every so often by clearing the current controls and recreating them.
When I run it, unless I close it soon afterwards, it will not close (with X, or alt|F4 etc). The only course of action is to use task manager.
Has anyone got any ideas as to what is causing it as it is driving me mad!
 
What is the code that you have in the timer?


DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
I am not sure why it does this, but I do have a work around solution that works for me.

Private Sub form_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Timer1.Enabled = False
Application.Exit()
End Sub

Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
Opps, I forgot some code ...

Private Sub form_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Timer1.Enabled = True Then
e.Cancel = True
Timer1.Enabled = False
Application.Exit()
End IF
End Sub

Becca

Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
Code for DotNetDoc:

Private Sub Timer1_Tick(...)
sec += 1
Call SetDateAndTimeDisplay() 'this shows the current date
'and time on the form
If sec >= REFRESH_INTERVAL Then
sec = 0
Call ClearControls() 'clears the txt and cbo boxes
Call RefreshData() 'requeries the database
Call FillActivityArray() 'Fills an array with a
'list of activities from the
'database
Call DisplayScreenInformation() 're-generates the new
'txt and cbo boxes
End If
End Sub

Thankyou both for your swift replies.
I shall try Rebecca's suggestion tomorrow (if i'm allowed on the computer on Xmas day!)
 
I believe this is a known issue with .NET, and caught me out on one of my previous projects.

I had the same problem - the application wouldn't close either by clicking the close button, firing the main form close event or by using ALT+F4.

I traced it to the fact that if a control has focus when it is removed from a collection, it prevents the form from closing, and thus the application from exiting. I got round it by moving focus away from the controls being removed before removing them.

I have since seen a number of newsgroup posts with similair problems and solutions, so yours may fall into this category.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top