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

Crash on exit, Timer did not expire

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello all,
I have the following problem:
I am using VB5, Professional Edition.
There is a timer (interval of about .5 sec) on the form, which is always active (displays some tooltips, but this is not relevant). When I close the program, sometimes (not always though) I got a crash due to the fact that timer did not expire and it's associated code was still executing after or while I unloaded the main form (form tried to re-load again as I am referencing it, or some of it's controls, inside Timer code).
I tried to disable the timer or change it's Interval to a very long value in Form_Unload event (to allow the form to unload safely) but it still happens, especially on slow machines. Using flags in timer event and checking them in a waiting loop when I unload the form, did not work either. Now it's harder to reproduce the bug but sometimes it still happens.
This is related to parallel processing, I need a way to know
that program pointer is not in the Timer event any more.

Thanks in advance for any suggestions,
MR - programmer
 
Have you tried using Error Handling to capture (and possible ignore) the error?

Other than that, I would say disable the Timer (you have already done that) and then maybe a "DoEvents" to make sure it takes effect.

-Bill
 
You may also want to do something like the following to insure that the timer event handling code completes:

dim InTimerEvent as boolean

Sub Form_Load
InTimerEvent = False
End Sub

Sub Form_Unload
MyTimer.Enabled = False
While (InTimerEvent = True)
DoEvents
Wend
End Sub

Sub MyTimer_Timer
ExecTimerCode
End Sub

Sub ExecTimerCode
InTimerEvent = True
< do what you gotta do >
InTimerEvent = False
End Sub
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
Thank you both for the suggestions, however I don't think using flags is the right solution. Code in Timer event may reference other forms or subroutines, etc so it may not be only Form_Load event triggered. I would have to add a lot flags everywhere in the program.
Obviously, Form_Unload and tmrTimerControl_Timer are process in parallel by VB, so I need another way (APIs?) to detect if VB has finished processing Timer code.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top