Click to See Complete Forum and Search --> : Abort() command not working for a Thread?


MikeKraken
January 26th, 2005, 02:03 AM
Hi, everybody. I'm having an issue with threading. One of my threads keeps on running even after I've called the End command and my GUI exits, but the process continues to run until the thread has finished. I use the Abort() command, but the thread does not abort. I've tried a variety of things (including Join(), Interrupt(), Sleep(), myThread = Nothing...), but I can't seem to get the thread to JUST STOP.

Here's the piece of code I'm running:


If Me.activeThread.ThreadState = ThreadState.Running Then
Me.activeThread.Abort()
End If


Also, an aside, when I was doing Suspend() followed by Abort(), I got the ThreadState of 130... I don't think that's supposed to happen!

Any help with this issue is greatly appreciated.

... Mike. *_*

SatyaV
January 26th, 2005, 11:06 AM
Just a WAG, but are you sure that your thread is already not in a wait state, like maybe an IO wait, or a Monitor wait etc when you are trying to kill it?

MikeKraken
January 26th, 2005, 06:31 PM
Well, I was trying this one as well...

Console.WriteLine("NO (before): " & Me.activeThread.ThreadState)
If Me.activeThread.IsAlive Then
Me.activeThread.Abort()
End If
Console.WriteLine("NO (after): " & Me.activeThread.ThreadState)


I always get a ThreadState of 0 (running) before checking if the thread is alive, and I was getting a ThreadState of 130 (???) afterward...

So as far as I know, it is actually running when I try to abort...

... Mike. O_o

MikeKraken
January 26th, 2005, 07:11 PM
I found out how to ensure that the thread closes when the rest of the application does.

Me.activeThread.IsBackground = True

Woo hoo!

... Mike. ^_^