472,331 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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 15131
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jerry Sievers | last post by:
Greetings Pythonists; I have limited experience with threaded apps and plenty with old style forked heavyweight multi-processing apps. Using...
10
by: Jacek Popławski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem...
0
by: Brett | last post by:
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...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread =...
3
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing an application that connects to the internet. Something like this: for res in socket.getaddrinfo(host, port, 0,...
5
by: Teja | last post by:
Hi all, Can any on help me out in killing a thread (i.e deleteing the reources like, stack ,memory etc) which is started with...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and...
4
by: Mathieu Prevot | last post by:
Hi, I have a threading.Thread class with a "for i in range(1,50)" loop within. When it runs and I do ^C, I have the error as many as loops. I...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, Is it possible "kill" the thread of Backgroundworker ? In my Dowork event, I have NOT While for do e.Cancel = true, only have a...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.