Thread Abort and Join

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

LVL 9
wellholeAsked:
Who is Participating?
 
ajb2222Connect With a Mentor Commented:
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
 
wellholeAuthor Commented:
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
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
It appears to be working for me...can you post more details?
0
 
wellholeAuthor Commented:
Ahh. I screwed up on this question. I'm going to start over with a better description.
0
All Courses

From novice to tech pro — start learning today.