473,466 Members | 1,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to kill a particular thread


Understand that when I start a thread, a number will be generated and is
able to get from GetHashCode method. But I would like to use this number
when I want to kill certain thread, anybody know how ??

Thanks
Regards
Nov 15 '05 #1
6 42850
If you can keep track of the hashcode why not just keep track of the thread
object itself?

Currently there is no managed API that will enumerate the managed thread
objects, so if all you have is the hashcode there is no documented way of
converting that back to a thread object. When you create the thread you
should save the thread reference and use that later when you want to stop
the thread.

"RickDee" <ch***********@agilent.com> wrote in message
news:u0****************@TK2MSFTNGP12.phx.gbl...

Understand that when I start a thread, a number will be generated and is
able to get from GetHashCode method. But I would like to use this number
when I want to kill certain thread, anybody know how ??

Thanks
Regards

Nov 15 '05 #2
Dave,

Hi. First of all thanks for your help.

So what are you saying is, if for example, I have the following statement :

th1 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));
th2= new System.Threading.Thread(new System.Threading.ThreadStart(abc.Run));
th3 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));

then I have to use :

th1.Abort()
th2.Abort()
th3.Abort()

right ?

My purpose is actually have a button on the Winform and every time the
button is clicked, it will call :

th1 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));

And I will then have another button on the winform that whe it is click,
user can select a particular thread to kill.

Thanks
Regards
"Dave" <kd******@wi.rr.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
If you can keep track of the hashcode why not just keep track of the thread object itself?

Currently there is no managed API that will enumerate the managed thread
objects, so if all you have is the hashcode there is no documented way of
converting that back to a thread object. When you create the thread you
should save the thread reference and use that later when you want to stop
the thread.

"RickDee" <ch***********@agilent.com> wrote in message
news:u0****************@TK2MSFTNGP12.phx.gbl...

Understand that when I start a thread, a number will be generated and is
able to get from GetHashCode method. But I would like to use this number
when I want to kill certain thread, anybody know how ??

Thanks
Regards


Nov 15 '05 #3
That's basically the idea.

FWIW, there are no guarantees that the thread will be aborted. This can
happen if it makes a call to unmanaged code - the thread wont be aborted
until it returns to managed code. Another is that the thread must be
running - if it is suspended it wont be aborted until it is resumed. Another
is that the thread can catch the abort and reset it. And I am not positive
about this, but I believe the thread must be in an alertable wait state for
the abort exception to get delivered, which means it must be blocked on a
synchronization object.
"RickDee" <ch***********@agilent.com> wrote in message
news:uZ**************@TK2MSFTNGP09.phx.gbl...
Dave,

Hi. First of all thanks for your help.

So what are you saying is, if for example, I have the following statement :
th1 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));
th2= new System.Threading.Thread(new System.Threading.ThreadStart(abc.Run)); th3 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));

then I have to use :

th1.Abort()
th2.Abort()
th3.Abort()

right ?

My purpose is actually have a button on the Winform and every time the
button is clicked, it will call :

th1 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));

And I will then have another button on the winform that whe it is click,
user can select a particular thread to kill.

Thanks
Regards
"Dave" <kd******@wi.rr.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
If you can keep track of the hashcode why not just keep track of the

thread
object itself?

Currently there is no managed API that will enumerate the managed thread
objects, so if all you have is the hashcode there is no documented way of converting that back to a thread object. When you create the thread you
should save the thread reference and use that later when you want to stop the thread.

"RickDee" <ch***********@agilent.com> wrote in message
news:u0****************@TK2MSFTNGP12.phx.gbl...

Understand that when I start a thread, a number will be generated and is able to get from GetHashCode method. But I would like to use this number when I want to kill certain thread, anybody know how ??

Thanks
Regards



Nov 15 '05 #4
Chirs,

Hi. :)

I think from the reply that you wrote, you definitely have the sample that I
need. I am interested in knowing how you are able to store them to a hash
table while creating the thread using GUID, and then able to kill them
individually.

Do you think you are able to shared one of the most simple example that you
have ? Appreciate that.

Thanks
Regards
"Chris Hornberger" <ch***@chornbe.com> wrote in message
news:53**************************@posting.google.c om...
Yep, that's about it. What I do... and I use self-managed threads VERY
sparingly... is add them to a hash table using a GUID or something
similar as the key. Then, when I want to kill them 'til they're dead
or just get status on them, I spin thru' the hash table and take care
of business. If I've aborted a thread, or it has completed (.IsAlive
== false), then I drop them from the hash if I'm happy they'll go away
or I've .Join()'d them without error.

"RickDee" <ch***********@agilent.com> wrote in message

news:<uZ**************@TK2MSFTNGP09.phx.gbl>...
Dave,

Hi. First of all thanks for your help.

So what are you saying is, if for example, I have the following statement :
th1 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));
th2= new System.Threading.Thread(new System.Threading.ThreadStart(abc.Run)); th3 = new System.Threading.Thread(new
System.Threading.ThreadStart(abc.Run));

then I have to use :

th1.Abort()
th2.Abort()
th3.Abort()

right ?

Nov 15 '05 #5
Absolutely. I'll post some sample a little bit later when I dig back
into code and can take a moment to copy/paste. I'm just at the
computer now for a few minutes to check messages and such before
heading out for the evening.

Back to you soon.
"RickDee" <ch***********@agilent.com> wrote in message news:<O3*************@TK2MSFTNGP09.phx.gbl>...
Chirs,

Hi. :)

I think from the reply that you wrote, you definitely have the sample that I
need. I am interested in knowing how you are able to store them to a hash
table while creating the thread using GUID, and then able to kill them
individually.

Do you think you are able to shared one of the most simple example that you
have ? Appreciate that.

Thanks
Regards

Nov 15 '05 #6
Absolutely. I'll post some sample a little bit later when I dig back
into code and can take a moment to copy/paste. I'm just at the
computer now for a few minutes to check messages and such before
heading out for the evening.

Back to you soon.
"RickDee" <ch***********@agilent.com> wrote in message news:<O3*************@TK2MSFTNGP09.phx.gbl>...
Chirs,

Hi. :)

I think from the reply that you wrote, you definitely have the sample that I
need. I am interested in knowing how you are able to store them to a hash
table while creating the thread using GUID, and then able to kill them
individually.

Do you think you are able to shared one of the most simple example that you
have ? Appreciate that.

Thanks
Regards

Nov 15 '05 #7

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 Python 2.3.3 on a Redhat 7.x machine. Wondering...
5
by: Blatwurst | last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the...
9
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...
2
by: Christopher Carnahan | last post by:
I need to figure out how to terminate a thread while it is blocked trying to create a COM object via interop. In a worker thread, I do something like this: Type t = null; Object...
1
by: AE_Cory | last post by:
I'm a n00b to Visual C++ and OOP, but not to programming in general. Here's the problem: Not knowing what I'm doing, I've made my VC++ application as a CLR Window Forms project. Now, I have a...
5
by: care02 | last post by:
Hi! I have the following problem: I have written a short Python server that creates an indefinite simulation thread that I want to kill when quitting (Ctrl-C) from Python. Googling around has...
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 never return. I am sure it has something to do...
20
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
John Dohn wrote: When I do this, I put a special value in the queue (like None) and in the worker thread, check for the special value and exit if found. Threads can also be marked as "daemon...
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 call to external COM. If I want cancel, calling...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.