Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Thread Abort and Join

Posted on 2010-11-17
4
Medium Priority
?
759 Views
Last Modified: 2012-05-10
I'm trying to abort and join onto a thread so that I don't write over the new thread work with the old thread work. But, its not behaving nicely. For some reason, Abort() and Join() isn't waiting for the Finally block to end. Any ideas?
Private t as Thread = Nothing

Sub StartThread()
  If Not t Is Nothing Then
    Console.WriteLine("Abort")
    t.Abort()
    t.Join()
  End If
  Console.WriteLine("New")
  t = New Thread(AddressOf SomeFunction)
  t.IsBackground = True
  t.Start()
End Sub

Sub SomeFunction()
  Try
    ' Do stuff
  Catch
    ' Ignore
  Finally
    ' Free up resources
    Console.WriteLine("Finally")
  End Try
End Sub

Open in new window

0
Comment
Question by:wellhole
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
ajb2222 earned 1000 total points
ID: 34158232
You might want to read this

http://www.interact-sw.co.uk/iangblog/2004/11/12/cancellation

The best way to stop a thread is to set a flag that you check periodicaly inside your thread.  this way the thread can determine when it is safe to exit.

Here is a good article on threads.

http://www.codeproject.com/KB/threads/ThreadingDotNet2.aspx
0
 
LVL 9

Author Comment

by:wellhole
ID: 34158278
I'm sorry ajb2222. That doesn't help. I can't wait seconds or minutes for a database query. Only abort can get out of that.
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 1000 total points
ID: 34159350
It appears to be working for me...can you post more details?
0
 
LVL 9

Author Comment

by:wellhole
ID: 34167805
Ahh. I screwed up on this question. I'm going to start over with a better description.
0

Featured Post

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question