469,306 Members | 1,903 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

How to kill thread?

I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the main
form closes. Looking at the threads window, I can see the class spawned by
the thread is still active. It's suspend status is 1. It is also using
100% cpu. How can I debug why this thread will not die?
Thanks,
Brett
Nov 21 '05 #1
9 14762
If you want the background thread to die when the parent app closes just set
the threads background property to true before you start it.

"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the main form closes. Looking at the threads window, I can see the class spawned by the thread is still active. It's suspend status is 1. It is also using
100% cpu. How can I debug why this thread will not die?
Thanks,
Brett

Nov 21 '05 #2
If you want the background thread to die when the parent app closes just set
the threads background property to true before you start it.

"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the main form closes. Looking at the threads window, I can see the class spawned by the thread is still active. It's suspend status is 1. It is also using
100% cpu. How can I debug why this thread will not die?
Thanks,
Brett

Nov 21 '05 #3
Brett,
Does this thread help:

http://groups-beta.google.com/group/...bbcf6fa6a59940
Hope this helps
Jay
"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the
main form closes. Looking at the threads window, I can see the class
spawned by the thread is still active. It's suspend status is 1. It is
also using 100% cpu. How can I debug why this thread will not die?
Thanks,
Brett

Nov 21 '05 #4
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.Background = True

I get this:
Constant cannot be the target of an assignment.

In summary, no - the the thread doesn't help.

Brett

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eh**************@TK2MSFTNGP15.phx.gbl...
Brett,
Does this thread help:

http://groups-beta.google.com/group/...bbcf6fa6a59940
Hope this helps
Jay
"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the
main form closes. Looking at the threads window, I can see the class
spawned by the thread is still active. It's suspend status is 1. It is
also using 100% cpu. How can I debug why this thread will not die?
Thanks,
Brett


Nov 21 '05 #5
Actually, I have the correct syntax and that seems to be working:
t.IsBackground = True

When the app is closing, I'm doing this:
If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

That probably isn't needed anymore. The second thread is closing without
it, now that the background is set to true.

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.Background = True

I get this:
Constant cannot be the target of an assignment.

In summary, no - the the thread doesn't help.

Brett

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eh**************@TK2MSFTNGP15.phx.gbl...
Brett,
Does this thread help:

http://groups-beta.google.com/group/...bbcf6fa6a59940
Hope this helps
Jay
"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the
main form closes. Looking at the threads window, I can see the class
spawned by the thread is still active. It's suspend status is 1. It is
also using 100% cpu. How can I debug why this thread will not die?
Thanks,
Brett



Nov 21 '05 #6
Brett,
Read the thread again: it states the IsBackground property, not the
background property.

http://msdn.microsoft.com/library/de...roundtopic.asp

Hope this helps
Jay

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.Background = True

I get this:
Constant cannot be the target of an assignment.

In summary, no - the the thread doesn't help.

Brett

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eh**************@TK2MSFTNGP15.phx.gbl...
Brett,
Does this thread help:

http://groups-beta.google.com/group/...bbcf6fa6a59940
Hope this helps
Jay
"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the
main form closes. Looking at the threads window, I can see the class
spawned by the thread is still active. It's suspend status is 1. It is
also using 100% cpu. How can I debug why this thread will not die?
Thanks,
Brett



Nov 21 '05 #7
Right, this will cause (the runtime I think) to kill the thread off when the
parent process dies.

The only thing you need to be careful of is what you are doing in that
thread. I am fairly certain that you have no control over what is being done
in that thread when it gets killed. If you are looping through a list for
instance your thread might die before the current loop is done.

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Actually, I have the correct syntax and that seems to be working:
t.IsBackground = True

When the app is closing, I'm doing this:
If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

That probably isn't needed anymore. The second thread is closing without
it, now that the background is set to true.

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.Background = True

I get this:
Constant cannot be the target of an assignment.

In summary, no - the the thread doesn't help.

Brett

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eh**************@TK2MSFTNGP15.phx.gbl...
Brett,
Does this thread help:

http://groups-beta.google.com/group/...+thread+remain
+AbortRequested%3F+group:microsoft.public.dotnet.l anguages.vb&_done=%2Fgroup
s%3Fas_q%3DWhy+does+thread+remain+AbortRequested%3 F%26num%3D10%26scoring%3Dr
%26hl%3Den%26ie%3DUTF-8%26as_epq%3D%26as_oq%3D%26as_eq%3D%26as_ugroup%3D micr
osoft.public.dotnet.languages.vb%26as_usubject%3D% 26as_uauthors%3D%26lr%3D%2
6as_drrb%3Dq%26as_qdr%3D%26as_mind%3D1%26as_minm%3 D1%26as_miny%3D1981%26as_m
axd%3D28%26as_maxm%3D2%26as_maxy%3D2005%26safe%3Do ff%26&_doneTitle=Back+to+S
earch&&d#12bbcf6fa6a59940

Hope this helps
Jay
"Brett" <no@spam.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I'm trying to kill a thread spawned this way:
Form1 spawns Class1 via Thread.start()

Here's my code to kill the thread:

If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

The above runs when I close the application. The abort is hit and the
main form closes. Looking at the threads window, I can see the class
spawned by the thread is still active. It's suspend status is 1. It is also using 100% cpu. How can I debug why this thread will not die?
Thanks,
Brett



Nov 21 '05 #8
It may not finish the entire loop but will finish the interaction it's in
correct?

Brett

"Ray Cassick" <rc******@nospam.enterprocity.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Right, this will cause (the runtime I think) to kill the thread off when
the
parent process dies.

The only thing you need to be careful of is what you are doing in that
thread. I am fairly certain that you have no control over what is being
done
in that thread when it gets killed. If you are looping through a list for
instance your thread might die before the current loop is done.

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Actually, I have the correct syntax and that seems to be working:
t.IsBackground = True

When the app is closing, I'm doing this:
If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

That probably isn't needed anymore. The second thread is closing without
it, now that the background is set to true.

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> No where in that post do I set the background property. If I try to do
> this:
> t.ThreadState.Background = True
>
> I get this:
> Constant cannot be the target of an assignment.
>
> In summary, no - the the thread doesn't help.
>
> Brett
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message > news:eh**************@TK2MSFTNGP15.phx.gbl...
>> Brett,
>> Does this thread help:
>>
>> http://groups-beta.google.com/group/...+thread+remain
+AbortRequested%3F+group:microsoft.public.dotnet.l anguages.vb&_done=%2Fgroup
s%3Fas_q%3DWhy+does+thread+remain+AbortRequested%3 F%26num%3D10%26scoring%3Dr
%26hl%3Den%26ie%3DUTF-8%26as_epq%3D%26as_oq%3D%26as_eq%3D%26as_ugroup%3D micr
osoft.public.dotnet.languages.vb%26as_usubject%3D% 26as_uauthors%3D%26lr%3D%2
6as_drrb%3Dq%26as_qdr%3D%26as_mind%3D1%26as_minm%3 D1%26as_miny%3D1981%26as_m
axd%3D28%26as_maxm%3D2%26as_maxy%3D2005%26safe%3Do ff%26&_doneTitle=Back+to+S
earch&&d#12bbcf6fa6a59940 >>
>>
>> Hope this helps
>> Jay
>>
>>
>> "Brett" <no@spam.com> wrote in message
>> news:u4**************@tk2msftngp13.phx.gbl...
>>> I'm trying to kill a thread spawned this way:
>>> Form1 spawns Class1 via Thread.start()
>>>
>>> Here's my code to kill the thread:
>>>
>>> If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
>>> (t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
>>> "WaitSleepJoin, Suspended") Then
>>> Else
>>> t.Abort()
>>> End If
>>>
>>> The above runs when I close the application. The abort is hit and
>>> the
>>> main form closes. Looking at the threads window, I can see the class
>>> spawned by the thread is still active. It's suspend status is 1. It is >>> also using 100% cpu. How can I debug why this thread will not die?
>>>
>>>
>>> Thanks,
>>> Brett
>>>
>>
>>
>
>



Nov 21 '05 #9
I am not sure.

"Brett" <no@spam.com> wrote in message
news:eG**************@TK2MSFTNGP14.phx.gbl...
It may not finish the entire loop but will finish the interaction it's in
correct?

Brett

"Ray Cassick" <rc******@nospam.enterprocity.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Right, this will cause (the runtime I think) to kill the thread off when
the
parent process dies.

The only thing you need to be careful of is what you are doing in that
thread. I am fairly certain that you have no control over what is being
done
in that thread when it gets killed. If you are looping through a list for instance your thread might die before the current loop is done.

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Actually, I have the correct syntax and that seems to be working:
t.IsBackground = True

When the app is closing, I'm doing this:
If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or
(t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
"WaitSleepJoin, Suspended") Then
Else
t.Abort()
End If

That probably isn't needed anymore. The second thread is closing without it, now that the background is set to true.

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> No where in that post do I set the background property. If I try to do > this:
> t.ThreadState.Background = True
>
> I get this:
> Constant cannot be the target of an assignment.
>
> In summary, no - the the thread doesn't help.
>
> Brett
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> news:eh**************@TK2MSFTNGP15.phx.gbl...
>> Brett,
>> Does this thread help:
>>
>>

http://groups-beta.google.com/group/...+thread+remain +AbortRequested%3F+group:microsoft.public.dotnet.l anguages.vb&_done=%2Fgroup s%3Fas_q%3DWhy+does+thread+remain+AbortRequested%3 F%26num%3D10%26scoring%3Dr %26hl%3Den%26ie%3DUTF-8%26as_epq%3D%26as_oq%3D%26as_eq%3D%26as_ugroup%3D micr osoft.public.dotnet.languages.vb%26as_usubject%3D% 26as_uauthors%3D%26lr%3D%2 6as_drrb%3Dq%26as_qdr%3D%26as_mind%3D1%26as_minm%3 D1%26as_miny%3D1981%26as_m axd%3D28%26as_maxm%3D2%26as_maxy%3D2005%26safe%3Do ff%26&_doneTitle=Back+to+S earch&&d#12bbcf6fa6a59940
>>
>>
>> Hope this helps
>> Jay
>>
>>
>> "Brett" <no@spam.com> wrote in message
>> news:u4**************@tk2msftngp13.phx.gbl...
>>> I'm trying to kill a thread spawned this way:
>>> Form1 spawns Class1 via Thread.start()
>>>
>>> Here's my code to kill the thread:
>>>
>>> If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or >>> (t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString =
>>> "WaitSleepJoin, Suspended") Then
>>> Else
>>> t.Abort()
>>> End If
>>>
>>> The above runs when I close the application. The abort is hit and
>>> the
>>> main form closes. Looking at the threads window, I can see the class >>> spawned by the thread is still active. It's suspend status is 1. It
is
>>> also using 100% cpu. How can I debug why this thread will not

die? >>>
>>>
>>> Thanks,
>>> Brett
>>>
>>
>>
>
>



Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Jerry Sievers | last post: by
10 posts views Thread by Jacek Popławski | last post: by
reply views Thread by Brett | last post: by
51 posts views Thread by Hans | last post: by
3 posts views Thread by Thomas Dybdahl Ahle | last post: by
5 posts views Thread by Teja | last post: by
18 posts views Thread by =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post: by
4 posts views Thread by Mathieu Prevot | last post: by
1 post views Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.