In VB6 - How to unload a form that is in the middle of having code executed on it due to a multi-threaded programming model (using timers)?
Posted on 2006-05-18
I have a program which there is a "CANCEL" button on a form which is supposed to unload the form in question and reactivate the form that called it. The problem is that a timer triggered event is updating picture boxes and while that occurs, this form (the one with the cancel button and picturboxes) will reappear even though I tried to unload it. How do I stop execution dead on a form before unloading it. ? Is this clear enough?
I tried to code an 'abort' global variable which I would set true when I'm about to unload the form (and the code in the timer would exit its loop if abort is set true (if abort then exit sub). Problem is that mostly this works but sometimes due to some timing constraint .. the form will disappear and reappear with a picturebox being updated nonetheless. Debugging shows the abort value to be true in all cases so I'm sure it's not a coding error (too simple to be coding error)
Please advise (p.s. I'm not a novice but programming multi-threaded apps in vb6 is something I'm not used to)