Results 1 to 2 of 2

Thread: Threading Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    96

    Threading Question

    I have a bunch of created threads... no problems with any of that. No problems at all actually, I just have a question.

    My question is, how would i go about aborting all threads dead in their tracks. I assume I would be using a For Each / Next loop, however I'm not sure of the actual pointers I'd be using for that loop. I've tried to go through the intellisense but have come up with nothing. I've read on google that using .Abort is a bad idea as well so before I take that route I was wondering if anyone could shed some light. I don't want the threads to finish doing whatever they were doing. I just want everything to stop with the click of a button. Is this possible?

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

    Re: Threading Question

    Calling Thread.Abort is the way to stop a thread dead in its tracks. The reason it can be a bad idea is that you might leave your application or some resource in an invalid state if you abort a thread when it's halfway through a task. It's generally better to set a flag somewhere and have the thread test that flag intermittently at safe points. It can then exit gracefully after performing the appropriate cleanup. If you do decide to go the Abort route then you will need to handle the ThreadAbortException that will be thrown, at which point you can perform some cleanup if required.
    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

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