Results 1 to 8 of 8

Thread: [RESOLVED] Canceling async calls

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Resolved [RESOLVED] Canceling async calls

    Hi,

    I'm using the MethodInvoker to set a background process to work.
    That process can take quite an amount of time, so I want the user to be able to cancel that.
    Now my worries are that if I use Application.Exit() it doesn't quit or that the thread is not cleaned up correctly.

    Any thoughts on this?
    Thanks.
    Delete it. They just clutter threads anyway.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Canceling async calls

    If you set the IsBackground property of a Thread to True before you Start it, it will not prevent the application closing. If that's not enough information then you're going to have to provide us with more information, i.e. exactly what you're doing, including code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Canceling async calls

    Ignore my comment.
    I seem to have mixed up the use of a background process with the use of the BackgroundWorker process.

    Appologies for the missinterpetation.
    Last edited by Optional; Jul 27th, 2010 at 06:57 AM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  4. #4
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Canceling async calls

    Application.Exit() is the same as calling Abort() on a thread, so if you've got proper cleanup, you're fine (back - but Application.Exit() will throw a security exception on some restricted accounts (it did on my school computers) so you should just set IsBackground. Environment.Exit() is different, though...

  5. #5
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Canceling async calls

    Environment.Exit returns a number back to the process/OS.
    It terminates the process with a number. IT also throws a Security Exception, depending on the account you are using and security setting configurations on the account or for applications and generally is used for console based apps (but not restricted to them)

    The thread in question can continue to run unless you set the IsBackground property to true on the Thread object, as highlighted earlier on.

    http://msdn.microsoft.com/en-us/libr...ackground.aspx for more information.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Canceling async calls

    Environment.Exit() also completely terminates every thread without raising the ThreadAbortException.

  7. #7
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Canceling async calls

    it is advisable to use the correct approach to exit your application rather than just "stabbing in the dark until you get it"

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #8
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Canceling async calls

    Well, he's already got it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width