Stop process on unload/terminate
I have a long process running with a doevent inside. If close button is clicked the application terminate/unloads, but the process still continues. How do I stop the process from continuing?
Assuming the long process is running in a loop, exit the loop. ;-)
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
I set the abort flag to true when the unload or terminate event occurs, but the loop continues. I think the program terminates before the system returns to the loop, and therfore it keeps going after the form has unloaded.
people here know what I think: I hate DoEvents.
Lithic, after the Unload event returns, the application goes back after the DoEvents. If after the DoEvents you make any call to any of the form components (like change a labels or so on), automatically the form gets loaded again, but it is hidden because the Show method was not called. Check careful your loop. After DoEvents, if the "stop" flag was set exit right away without doing anything. In case, you can use two flags: a normal stop and a 'I am unloading' flag.
Very interesting, thanks for the insight, i'll try that now.
Ok, I tried it by declaring a variable (module wide) blnUnload. In both the form_unload and form_terminate subs I set blnUnload to true. The line following the doevents line in my loop is "if blnUnload = true then unload me".
it still doesnt work though.
mrstaf, I'm keen to know what you do instead of using doevents...
How about in the Form_Unload event you do a SendMessage with the WM_QUIT message to the other app?
How come your doing a loop anyways? Maybe we can figure a better way.
Thanks for the reply.
The loop counts the number of lines in a text file. Since the application is designed for use with very big files (sometimes more than 1 million lines) it can take a while to do the count.
If I compile the program and exit I can tell that the count has stopped because there is no harddrive activity, but I assume that the program is still using memory because the form might still be loaded?
I'm a newbie still so I'm not familiar with SendMessage but the process isn't running in a separate application.
you can't call "unload me" because the form is unloding... please change to
Originally Posted by Lithic
if blnunload then exit sub
(no need for the "= true")
See if I can find the my threads about DoEvents (there should be plenty of them).
...exit sub works perfectly, thanks!
And i'll try to get out of the habit of using "= true" for booleans.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center