Solved

Thread Abort and Join

Posted on 2010-11-17
4
720 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 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 86

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

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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