-
Stop process on unload/terminate
Hiya,
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?
Cheers,
Lithic.
-
Assuming the long process is running in a loop, exit the loop. ;-)
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Hi Phil,
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.
Marco
-
Ahhh, claro!
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.
-
 Originally Posted by Lithic
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...
you can't call "unload me" because the form is unloding... please change to
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).
Marco
-
Absolutely Correct!
...exit sub works perfectly, thanks!
And i'll try to get out of the habit of using "= true" for booleans.
Cheers,
Lithic
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks