Stop process on unload/terminate


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Stop process on unload/terminate

  1. #1
    Join Date
    Dec 2004
    Posts
    110

    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.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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!

  3. #3
    Join Date
    Dec 2004
    Posts
    110
    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.

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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

  5. #5
    Join Date
    Dec 2004
    Posts
    110
    Ahhh, claro!

    Very interesting, thanks for the insight, i'll try that now.

  6. #6
    Join Date
    Dec 2004
    Posts
    110
    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...

  7. #7
    Join Date
    Mar 2005
    Location
    Los Angeles, Calif. AKA: Gangsta Yoda™
    Posts
    455
    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer code questions via PMs.
    Microsoft MVP 2006-2009
    Office Development FAQ (VBA, VB6, VB.NET, C#)
    Software Engineer MCP (VB6 & .NET)
    Reps & Rating PostsVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address List

  8. #8
    Join Date
    Dec 2004
    Posts
    110
    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.

  9. #9
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Quote 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

  10. #10
    Join Date
    Dec 2004
    Posts
    110

    Thumbs up

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center