Solved

Thread Abort and Join

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now