473,837 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
+ 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 42879
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******** ********@TK2MSF TNGP12.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.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.Run));
th2= new System.Threadin g.Thread(new System.Threadin g.ThreadStart(a bc.Run));
th3 = new System.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.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.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.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******** ******@TK2MSFTN GP12.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******** ********@TK2MSF TNGP12.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******** ******@TK2MSFTN GP09.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.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.Run));
th2= new System.Threadin g.Thread(new System.Threadin g.ThreadStart(a bc.Run)); th3 = new System.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.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.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.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******** ******@TK2MSFTN GP12.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******** ********@TK2MSF TNGP12.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.goo gle.com...
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******* *******@TK2MSFT NGP09.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.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.Run));
th2= new System.Threadin g.Thread(new System.Threadin g.ThreadStart(a bc.Run)); th3 = new System.Threadin g.Thread(new
System.Threadin g.ThreadStart(a bc.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******* ******@TK2MSFTN GP09.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******* ******@TK2MSFTN GP09.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
18904
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.
5
10944
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 Accept() returns, the thread spins off another thread to handle the request, and then calls Accept() again. This all works fine except that I can find no way to kill the thread that is blocked in the Accept() call when I want to shut down the server. ...
9
15290
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()
2
3509
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 activatedObject = null; Legacy.IScheduled comObject = null; t = Type.GetTypeFromProgID(ProgID);
1
1727
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 process that is lauched by pushing a button. The code for this process is inside the Button_Click event handler for that particular button. The problem is that I need to be able to kill that process with another button. I have a global flag...
5
10611
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 not given me any hints on how to cleanly kill running threads before exiting. Any help is appreciated! Carl
18
10250
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...
20
5108
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 threads" (see docs for threading.Thread objects). This will make the application terminate if only "daemon threads" are left. So best would probably be soemthing like
1
10394
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
9840
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
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10565
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...
1
10623
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7806
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7000
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
5668
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...
0
5847
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
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

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.