Solved

Thread Abort and Join

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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