Solved

Thread Abort and Join

Posted on 2010-11-17
4
706 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
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
ajb2222 earned 250 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 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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