473,734 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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 15284
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******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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.B ackground = 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******** ******@TK2MSFTN GP15.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******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ********@TK2MSF TNGP12.phx.gbl. ..
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.B ackground = 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******** ******@TK2MSFTN GP15.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******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ********@TK2MSF TNGP12.phx.gbl. ..
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.B ackground = 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******** ******@TK2MSFTN GP15.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******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ********@TK2MSF TNGP15.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ********@TK2MSF TNGP12.phx.gbl. ..
No where in that post do I set the background property. If I try to do
this:
t.ThreadState.B ackground = 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******** ******@TK2MSFTN GP15.phx.gbl...
Brett,
Does this thread help:

http://groups-beta.google.com/group/...+thread+remain
+AbortRequested %3F+group:micro soft.public.dot net.languages.v b&_done=%2Fgrou p
s%3Fas_q%3DWhy+ does+thread+rem ain+AbortReques ted%3F%26num%3D 10%26scoring%3D r
%26hl%3Den%26ie %3DUTF-8%26as_epq%3D%2 6as_oq%3D%26as_ eq%3D%26as_ugro up%3Dmicr
osoft.public.do tnet.languages. vb%26as_usubjec t%3D%26as_uauth ors%3D%26lr%3D% 2
6as_drrb%3Dq%26 as_qdr%3D%26as_ mind%3D1%26as_m inm%3D1%26as_mi ny%3D1981%26as_ m
axd%3D28%26as_m axm%3D2%26as_ma xy%3D2005%26saf e%3Doff%26&_don eTitle=Back+to+ S
earch&&d#12bbcf 6fa6a59940

Hope this helps
Jay
"Brett" <no@spam.com> wrote in message
news:u4******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******@nospa m.enterprocity. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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******** ********@TK2MSF TNGP15.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ********@TK2MSF TNGP12.phx.gbl. ..
> No where in that post do I set the background property. If I try to do
> this:
> t.ThreadState.B ackground = 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******** ******@TK2MSFTN GP15.phx.gbl...
>> Brett,
>> Does this thread help:
>>
>> http://groups-beta.google.com/group/...+thread+remain
+AbortRequested %3F+group:micro soft.public.dot net.languages.v b&_done=%2Fgrou p
s%3Fas_q%3DWhy+ does+thread+rem ain+AbortReques ted%3F%26num%3D 10%26scoring%3D r
%26hl%3Den%26ie %3DUTF-8%26as_epq%3D%2 6as_oq%3D%26as_ eq%3D%26as_ugro up%3Dmicr
osoft.public.do tnet.languages. vb%26as_usubjec t%3D%26as_uauth ors%3D%26lr%3D% 2
6as_drrb%3Dq%26 as_qdr%3D%26as_ mind%3D1%26as_m inm%3D1%26as_mi ny%3D1981%26as_ m
axd%3D28%26as_m axm%3D2%26as_ma xy%3D2005%26saf e%3Doff%26&_don eTitle=Back+to+ S
earch&&d#12bbcf 6fa6a59940 >>
>>
>> Hope this helps
>> Jay
>>
>>
>> "Brett" <no@spam.com> wrote in message
>> news:u4******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or
>>> (t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
>>> "WaitSleepJ oin, 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******** ******@TK2MSFTN GP14.phx.gbl...
It may not finish the entire loop but will finish the interaction it's in
correct?

Brett

"Ray Cassick" <rc******@nospa m.enterprocity. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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******** ********@TK2MSF TNGP15.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 = "SuspendedReque sted, WaitSleepJoin") Or
(t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
"WaitSleepJ oin, 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******** ********@TK2MSF TNGP12.phx.gbl. ..
> No where in that post do I set the background property. If I try to do > this:
> t.ThreadState.B ackground = 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******** ******@TK2MSFTN GP15.phx.gbl...
>> Brett,
>> Does this thread help:
>>
>>

http://groups-beta.google.com/group/...+thread+remain +AbortRequested %3F+group:micro soft.public.dot net.languages.v b&_done=%2Fgrou p s%3Fas_q%3DWhy+ does+thread+rem ain+AbortReques ted%3F%26num%3D 10%26scoring%3D r %26hl%3Den%26ie %3DUTF-8%26as_epq%3D%2 6as_oq%3D%26as_ eq%3D%26as_ugro up%3Dmicr osoft.public.do tnet.languages. vb%26as_usubjec t%3D%26as_uauth ors%3D%26lr%3D% 2 6as_drrb%3Dq%26 as_qdr%3D%26as_ mind%3D1%26as_m inm%3D1%26as_mi ny%3D1981%26as_ m axd%3D28%26as_m axm%3D2%26as_ma xy%3D2005%26saf e%3Doff%26&_don eTitle=Back+to+ S earch&&d#12bbcf 6fa6a59940
>>
>>
>> Hope this helps
>> Jay
>>
>>
>> "Brett" <no@spam.com> wrote in message
>> news:u4******** ******@tk2msftn gp13.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 = "SuspendedReque sted, WaitSleepJoin") Or >>> (t.ThreadState. ToString = "Suspended" ) Or (t.ThreadState. ToString =
>>> "WaitSleepJ oin, 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
18892
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 Python 2.3.3 on a Redhat 7.x machine. Wondering if there is a simple way from a main python program to kill a running thread? I see with the 'threading' module the way daemonic threads behave when the main program finishes.
10
9884
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 is, that I need some timeout. I need to say for example: os.system("someapplication.exe") and kill it, if it waits longer than let's say 100 seconds
0
426
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 (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or (t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString = "WaitSleepJoin, Suspended") Then Else t.Abort()
51
54858
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 = threading.Thread(target=Loop.testLoop) thread.start() # This thread is expected to finish within a second
3
2874
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, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) Now if the user press the cancel button, I'd like the connection to imidiatly stop. I run
5
2681
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 win32process.beginthreadex()??? Rite now, I am suspending the thread. But any pointers as to how to delete the thread permanently? Its pretty urgent... Please...
18
10240
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 never return. I am sure it has something to do with weirdness going on with the server I am talking to. Anyhow, this locked up state happens once in a while (maybe once per day) and I can't figure out how to deal with the locked up thread. If I issue a Thread.Abort() the exception never...
4
2372
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 would like to catch this exception (and if possible do some cleanup like in C pthreads) so the program finishes cleanly. Where and how can I do this ? in __run__ ? __init__ ? a try/except stuff ? Thanks, Mathieu
1
10385
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 call to external COM. If I want cancel, calling CancelAsync, not cancels the call to COM. How I can do it , please ? Any suggestions will be very appreciated.
0
8951
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9458
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9187
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6040
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3266
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.